Getting ... yelp_soup is not defined when writing scraper 脚本

Getting ... yelp_soup is not defined when writting scraper script

我遇到错误:

yelp_soup is not defined when writting scraper script

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

这是 link 到 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())