学习爬虫过程当中,使用beautiful soup,爬取糗事百科内容,遇到问题。html
<div class="col1 old-style-col1">
要查找class,怎么也不行python
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_,找了你很久。3d
修改后的代码以下htm
con = soup.find('div',class_='col1 old-style-col1')blog
报错信息终于消失了,开心,能够继续作个人项目二舆情监控系统了。get