我正在尝试使用PyCharm中的python来使用requests_html进行web抓取。下面的代码不会使用与我的PyCharm项目相同的venv返回终端中的错误(python3.8.10),但是当我使用PyCharm时会得到一个错误。
守则:
from requests_html import HTMLSession
session = HTMLSession
response = session.get('https://python.org')在PyCharm中运行PyCharm之后,我会得到以下错误:
Traceback (most recent call last):
File "/usr/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 11, in <module>
TypeError: get() missing 1 required positional argument: 'url'如何使PyCharm成功地运行session.get()
发布于 2022-03-08 04:05:01
看起来您不小心遗漏了这里的括号:
session = HTMLSession
所以:session.get -> <function Session.get at 0x10377e550>.
help(session.get) -> get(self, url, **kwargs).
它试图在类get()上调用HTMLSession方法,而不是调用类的实例,即会话。在这种情况下,函数接收字符串参数而不是隐式self参数,而不接收url参数。
鉴于在下列情况下:
session = HTMLSession()
session.get -> <bound method Session.get of <requests_html.HTMLSession object at 0x10276c460>>
help(session.get) -> get(url, **kwargs).
session.get('https://python.org') -> <Response [200]>.
https://stackoverflow.com/questions/71389717
复制相似问题