当我尝试通过其网站示例使用新模块 requests_html 时,我发现控制台在标题中显示了信息。
pip install requests_html
控制台消息:
Traceback (most recent call last):
File "C:/Users/owlish/PycharmProjects/python34/requests.py", line 2, in <module>
from requests_html import HTMLSession
File "C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py", line 10, in <module>
import requests
File "C:\Users\owlish\PycharmProjects\python34\requests.py", line 2, in <module>
from requests_html import HTMLSession
ImportError: cannot import name 'HTMLSession' from 'requests_html' (C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py)
代码:
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')
我希望它能正常工作,例如示例https://html.python-requests.org/。
答案 0 :(得分:1)
在AhmedHawary的帮助下,我找到了错误的原因:我有一个名为 requests.py 的文件,该文件与 keywords 冲突。重命名文件名后,它运行良好。