爬虫错误总结录

一、目标网站编码utf-8,通过requests请求返回text方法,用到xpath上报错

Traceback (most recent call last):
  File "/python_project/app_data/parse_async/setup_parse.py", line 49, in <module>
    get_urls(link)
  File "/python_project/app_data/parse_async/setup_parse.py", line 44, in get_urls
    tree = etree.HTML(html)
  File "src/lxml/etree.pyx", line 3170, in lxml.etree.HTML
  File "src/lxml/parser.pxi", line 1872, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
值错误:不支持带编码声明的Unicode字符串。请使用不带声明的字节输入或XML片段。

解决:

将`html = requests.get(url=base_url, headers=headers).text` 改为`html = requests.get(url=base_url, headers=headers).content` 即可

posted @ 2019-05-10 00:17  Alive_2020  阅读(385)  评论(0编辑  收藏  举报