从 requests_html 成功 PyCharm 运行 session.get()
Make PyCharm successfully run session.get() from requests_html
我正在尝试使用 requests_html 在 PyCharm 中使用 python 进行网络抓取。以下代码在使用与我的 PyCharm 项目(python 3.8.10)相同的 venv 的终端中没有 return 错误,但是当我使用 PyCharm 我得到一个错误。
代码:
from requests_html import HTMLSession
session = HTMLSession
response = session.get('https://python.org')
在 PyCharm 中 运行ning response = session.get('https://python.org')
之后,我得到这个错误:
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()
?
您似乎不小心遗漏了此处的括号:
session = HTMLSession
所以:session.get
--> <function Session.get at 0x10377e550>
.
help(session.get)
--> get(self, url, **kwargs)
.
它试图在 class HTMLSession 而不是 class 的实例(即会话)上调用 get()
方法。在这种情况下,该函数接收字符串参数代替隐式 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]>
.
我正在尝试使用 requests_html 在 PyCharm 中使用 python 进行网络抓取。以下代码在使用与我的 PyCharm 项目(python 3.8.10)相同的 venv 的终端中没有 return 错误,但是当我使用 PyCharm 我得到一个错误。
代码:
from requests_html import HTMLSession
session = HTMLSession
response = session.get('https://python.org')
在 PyCharm 中 运行ning response = session.get('https://python.org')
之后,我得到这个错误:
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()
?
您似乎不小心遗漏了此处的括号:
session = HTMLSession
所以:session.get
--> <function Session.get at 0x10377e550>
.
help(session.get)
--> get(self, url, **kwargs)
.
它试图在 class HTMLSession 而不是 class 的实例(即会话)上调用 get()
方法。在这种情况下,该函数接收字符串参数代替隐式 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]>
.