https://github.com/famousdraw

爬虫beautiful soup遇到的小问题

学习爬虫过程中,使用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')

 

 

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

------------------------------------------------------------------------------------------

 如果你觉得文章有用,欢迎打赏

 

 

posted on 2020-04-24 08:35  红色MINI  阅读(260)  评论(0编辑  收藏  举报

导航