我的requests-html模块怎么了?

 from requests_html import HTMLSession
  File "C:\Users\凡人\AppData\Local\Programs\Python\Python39\lib\site-packages\requests_html.py", line 11, in <module>
    from pyquery import PyQuery
  File "C:\Users\凡人\AppData\Local\Programs\Python\Python39\lib\site-packages\pyquery\__init__.py", line 5, in <module>
    from .pyquery import PyQuery  # NOQA
  File "C:\Users\凡人\AppData\Local\Programs\Python\Python39\lib\site-packages\pyquery\pyquery.py", line 12, in <module>
    import lxml.html
  File "C:\Users\凡人\AppData\Local\Programs\Python\Python39\lib\site-packages\lxml\html\__init__.py", line 87, in <module>
    _rel_links_xpath = etree.XPath("descendant-or-self::a[@rel]|descendant-or-self::x:a[@rel]",
AttributeError: 'function' object has no attribute 'XPath'

本人分别在pycharm和vscode中测试了都报出这样的问题.请高手给予指点.

我找到问题了,requests-html关联的lxml库没有升级造成的问题.刚刚重新升级安装了lxml4.6.3版本库,问题解决了.

请求时加一个头部信息:

headers={"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"}

 

from requests_html import HTMLSession

# 获取请求对象
session = HTMLSession()
headers = {
    'user-agent':
    'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36'
}
sina = session.get('https://news.sina.com.cn/', headers=headers)
print(sina.text)

我是加过请求头的,报错提示是库文件中的解析出错了,这是我刚刚从requests_html库中找的一个实例,也一样报错.
  _rel_links_xpath = etree.XPath("descendant-or-self::a[@rel]|descendant-or-self::x:a[@rel]",
AttributeError: 'function' object has no attribute 'XPath'