【发布时间】:2020-04-02 04:20:29
【问题描述】:
我正在尝试抓取类似于 Yelp 的食品评论网站。我已经完成了抓取单个页面并获取单个餐厅信息的部分。但是我遇到过这个问题,网站有超过 900k 个列表,但页码最多只有 60 个,最多显示 1200 个列表。即使我缩小过滤器并遍历每个过滤器选项,每个过滤器下的列表仍将超过 1200 个。 我正在使用 requests 和 beautifulsoup 进行抓取。 有更好或更有效的解决方案的想法吗?
def crawl_listing(url):
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
#code for obtaining url of each listing on this page
return (#dict of restaurant names and urls)
def crawl_detail(url):
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
#code for getting all needed information about the restaurant
def main():
full_list = []
for page in range(30):
address = f"https://www.example.com/list/{page}"
full_list = full_list + crawl_listing(address)
for restaurant in full_list:
crawl_detail(restaurant['url'])
【问题讨论】:
标签: python web-scraping data-science