【发布时间】:2020-03-29 05:33:31
【问题描述】:
我正在尝试使用 Beautiful Soup 从Kickstarter webpage 中抓取项目的 URL。我正在使用以下代码:
import requests
from bs4 import BeautifulSoup
url = 'https://www.kickstarter.com/discover/advanced?category_id=28&staff_picks=1&sort=newest&seed=2639586&page=1'
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
project_name_list = soup.find(class_='grid-row flex flex-wrap')
project_name_list_items = project_name_list.find_all('a')
print(project_name_list_items)
for project_name in project_name_list_items:
links = project_name.get('href')
print(links)
但这是我得到的输出:
[<a class="block img-placeholder w100p"><div class="img-placeholder bg-grey-400 absolute t0 w100p"></div></a>, <a class="block img-placeholder w100p"><div class="img-placeholder bg-grey-400 absolute t0 w100p"></div></a>, <a class="block img-placeholder w100p"><div class="img-placeholder bg-grey-400 absolute t0 w100p"></div></a>, <a class="block img-placeholder w100p"><div class="img-placeholder bg-grey-400 absolute t0 w100p"></div></a>, <a class="block img-placeholder w100p"><div class="img-placeholder bg-grey-400 absolute t0 w100p"></div></a>, <a class="block img-placeholder w100p"><div class="img-placeholder bg-grey-400 absolute t0 w100p"></div></a>]
None
None
None
None
None
None
我尝试了几种方法,例如:
for link in soup.find_all('a'):
print(link.get('href'))
但仍然没有结果。 此外,我正在抓取的这个页面在页面末尾有一个“加载更多”部分。如何获取该部分的 URL? 感谢您的帮助。
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup