用Beautifulsoup抓取Craigslist位置或城市的最佳方法是什么?



我对Python真的很陌生,从昨天开始我就尝试使用Beautifulsoup来抓取craigslist帖子的位置(城市或谷歌地图信息(。

我尝试了一种在网站上找到的方法:使用Beautiful Soup从非类部分获取数据

但当我使用:

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)

相关内容

最新更新