得到..编写抓取程序脚本时未定义yelp_soup



我收到错误:

编写抓取程序脚本时未定义yelp_soup

我不知道为什么,这是从 udemy 课程复制的代码,但它对他们有用。为什么?

这是指向 GitHub 的链接,我从那里复制了它作为最后的手段,但不起作用:

https://github.com/codingforentrepreneurs/30-Days-of-Python/blob/master/Day%2021%20-%2023/scrape/code/scape.py

有什么建议吗?我尝试了一些想法,但没有任何改变?

为了达到目的,我做了一些修改。运行以下命令,如果您遇到其他问题,请告诉我:

import requests
from bs4 import BeautifulSoup
base_url = 'https://www.yelp.com/search?find_desc=Restaurants&find_loc='
loc = 'Newport+Beach,+CA'
page = 10
url = base_url + loc + "&start=" + str(page)
yelp_soup = BeautifulSoup(requests.get(url).text, 'lxml')
for biz in yelp_soup.find_all(class_='biz-listing-large'):
    title = biz.find_all(class_='biz-name')[0].text
    address = biz.select('address,.biz-parent-container')[0].text
    phone = biz.find_all(class_='biz-phone')[0].text
    print(title.strip(),address.strip(),phone.strip())

最新更新