最初にページからすべてのリンクを取得しようとしていますが、「次へ」ボタンのURLを取得して、ページがなくなるまでループしています。しかし、何らかの理由でBeautifulSoupが2番目のページを解析することはありません。最初のものだけを停止してから停止します。Python BeautifulSoup - 複数のページをループする
難解ですが、ここではコードを分かりやすくする必要があります説明しようとしているもの:
#this site holds the first page that it should start looping on.. from this page i want to reach page 2, 3, etc.
webpage = urlopen('www.first-page-with-urls-and-next-button.com').read()
soup = BeautifulSoup(webpage)
for tag in soup.findAll('a', { "class" : "next" }):
print tag['href']
print "\n--------------------\n"
#next button is relative url so append it to main-url.com
soup = BeautifulSoup('http://www.main-url.com/'+ re.sub(r'\s', '', tag['href']))
#for some reason this variable only holds the tag['href']
print soup
for taggen in soup.findAll('a', { "class" : "homepage target-blank" }):
print tag['href']
# Read page found
sidan = urlopen(taggen['href']).read()
# get title
Titeln = re.findall(patFinderTitle, sidan)
print Titeln
アイデアはありますか?英語が苦手な方には申し訳ありませんが、私は叩かれないことを願っています:)私はそれを貧乏人に説明したかどうか尋ねて、もう少し説明するために全力を尽くします。ああ、私はPythonを初めて使っています。(あなたが想像したように)
が、 BeatifulSoup()をURLに直接渡す時間? – larsks