import urllib2 from bs4 import BeautifulSoup url = 'http://baike.baidu.com/view/21087.htm' response = urllib2.urlopen(url) if response.getcode() != 200: print 'error' html_cont = response.read() soup = BeautifulSoup(html_cont, 'html.parser', from_encoding="utf-8") # <dd class="lemmaWgt-lemmaTitle-title"><h1>.com</h1> #print html_cont title_node = soup.find('dd', class_="lemmaWgt-lemmaTitle-title") print title_node.find('h1').get_text()
下面是报错
Traceback (most recent call last): File "/home/kinredon/PycharmProjects/imooc2.7/test/testbaike.py", line 16, in <module> print title_node.find('h1').get_text() AttributeError: 'NoneType' object has no attribute 'find'
经过多次测试,问题就出在soup.find()那,这个该怎么解决啊
空34
相关分类