View More Campaigns
ボタンをクリックすることから、ブラウザには、以下のURLを要求します:
あなたのように始まる出力を与える
from bs4 import BeautifulSoup
import requests
page = 1
links = set()
length = 0
while True:
print("Page {}".format(page))
gofundme = requests.get('https://www.gofundme.com/mvc.php?route=category/loadMoreTiles&page={}&term=sport&country=GB&initialTerm='.format(page))
soup = BeautifulSoup(gofundme.content, "html.parser")
links.update([a['href'] for a in soup.find_all('a', href=True)])
# Stop when no new links are found
if len(links) == length:
break
length = len(links)
page += 1
for link in sorted(links):
print(link)
:
https://www.gofundme.com/100-round-kumite-rundraiser
https://www.gofundme.com/10k-challenge-for-disabled-sports
https://www.gofundme.com/1yeti0
https://www.gofundme.com/2-marathons-1-month
https://www.gofundme.com/23yq67t4
https://www.gofundme.com/2fwyuwvg
は返されたリンクの一部が重複しているので、set
は、これを回避するために使用されます。 新しいリンクが表示されなくなるまで、スクリプトは新しいページを要求し続けます。これは約18ページで発生します。
*常に質問に目を向けるだけの場合は、一般的な[python]タグを使用してください。 –