學習爬蟲過程當中,使用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