2017-11-11 26 views
-1

时yelp_soup没有定义,我发现了错误:获取...书面方式刮刀脚本

yelp_soup is not defined when writting scraper script

我不知道为什么,这是代码从udemy过程中复制,但它为他们工作。这是为什么?

这是链接,从那里我复制它作为最后的手段GitHub的,但不工作:

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

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

回答

0

我修改了一些以达到目的。运行此并让我知道如果您遇到更多问题:

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()) 
+0

为什么我仍然越来越。名称yelp_soup没有定义?仍然出现错误:/ –

+0

你确定你已经安装了'requests'和'BeautifulSoup'库吗? – SIM

+0

我现在做了。我删除整个文件夹,重做一切,再次重新安装库,现在它完美地工作。不知道为什么 –