首页 > 其他 > 详细

爬虫beautiful soup遇到的小问题

时间:2020-04-24 10:06:17      阅读:90      评论:0      收藏:0      [点我收藏+]

学习爬虫过程中,使用beautiful soup,爬取糗事百科内容,遇到问题。

技术分享图片

 

 


<div class="col1 old-style-col1">
要查找class,怎么也不行

def get_content(html, page):
output = """第{}页 作者:{} 性别:{} 年龄:{} 点赞:{} 评论:{}\n{}\n------------\n"""
soup = BeautifulSoup(html, ‘html.parser‘)
print(soup)
#con = soup.find(id=‘content-left‘)
con = soup.find(‘div‘,class=‘col1 old-style-col1‘)
print(con)

技术分享图片

 

 


后来才知道,class是python的保留字,加一个下划线就可以了。开心。class_,找了你好久。

修改后的代码如下

con = soup.find(‘div‘,class_=‘col1 old-style-col1‘)

技术分享图片

 

 

报错信息终于消失了,开心,可以继续做我的项目二舆情监控系统了。

 

爬虫beautiful soup遇到的小问题

原文:https://www.cnblogs.com/z-cm/p/12765139.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!