bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.

用python爬取网站信息时出现Traceback (most recent call last):
  File "D:/untitled/day04/0403.py", line 5, in <module>
    soup= BeautifulSoup(wb_data.text,'lxml')
  File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\bs4\__init__.py", line 196, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

表示缺少lxml解释器在Dos界面安装一个再重新启动就可以解决问题bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.

 然后又出现

UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 19763: illegal multibyte sequence

解决方法:

soup= BeautifulSoup(wb_data.text,'lxml').encode('gbk','ignore')

问题是这样的,网页的数据应该是'utf-8'编码,这个可以在网页的head上面看得到,然后你爬网页的时候会把它转化成Unicode,出问题的是在print()这儿,对于print()这个函数,他需要把内容转化为'gbk'编码才能显示出来. 然后解决办法是这样,你在转化后的Unicode编码的string后面,加上 .encode('GBK','ignore').decode('GBk') 也就是先用gbk编码,忽略掉非法字符,然后再译码,是不是很有道理 应该是这样的.

 

 

上一篇:denied: requested access to the resource is denied


下一篇:使用Ehcache缓存同步启动时抛出异常net.sf.ehcache.CacheException: Can't assign requested address