报错No handlers could be found for logger "bs4.dammit"
运行代码时报错:No handlers could be found for logger "bs4.dammit"
# coding:utf8 import urllib2 import bs4 import re url = 'http://www.baidu.com' request = urllib2.Request(url) request.add_header('user-agent', 'Mozilla/5.0') response = urllib2.urlopen(request) html_doc = response.read() soup = bs4.BeautifulSoup(html_doc, 'html.parser', from_encoding='utf-8') links = soup.find_all('a') link = soup.find('a', href=re.compile(r".*preferences.*")) print link.name, link['href'], link.get_text()
这个代码运行时而可以成功运行,时而报上述错误。不能运行的时候等两分钟再运行又可以成功输出了。