[英]What's the better way to scrape Craigslist location or city with Beautifulsoup?
我真的是 Python 新手,从昨天开始我就尝试使用 Beautifulsoup抓取craigslist 帖子的位置(城市或谷歌地图信息)。
我尝试了一种在网站上找到的方法: 使用美丽的汤从非类部分获取数据
但是当我使用:
for url in (url_list):
page2 = requests.get(url)
soup = BeautifulSoup(page2.content, 'html.parser')
for address in soup.findAll("div", {"class": "mapaddress"}):
addressText = ''.join(address.findAll(text=True))
location.append(addressText)
我有NameError: name 'addressText' is not defined
在最后一行,我不明白为什么。
如果有人可以提供帮助或提供其他解决方案,我将不胜感激,
非常感谢,
我认为问题在于您没有正确缩进代码。 尝试将其修改为
for address in soup.findAll("div", {"class": "mapaddress"}):
addressText = ''.join(address.findAll(text=True))
location.append(addressText)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.