IT序号网

python之Python 爬虫的开端

exmyth 2023年08月20日 编程语言 129 0

<分区>

我正在自学 Python,方法是实践而不是阅读。 当我运行这段代码时,终端没有显示错误,但什么也没有发生,尽管在我看来这应该是从这个列表中检索地址。

我调用这些数据的方式有问题吗?

import requests 
from bs4 import BeautifulSoup 
 
url = ("http://www.gym-directory.com/listing/bulldog-gym/") 
r = requests.get(url) 
 
soup = BeautifulSoup(r.content, "html.parser") 
print soup.prettify() 
 
listing_data = soup.find_all("div", {"class":"tab-contents"}) 
for item in listing_data: 
    print item.contents[0].find_all("span",{"class":"wlt_shortcode_map_location"})[0].text 

评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!