meta
是 Scrapy Request
特有的,而 python-requests 的 request 没有 meta
参数,因此会引发 TypeError
异常。
要使用 Splash 和 python-requests,阅读 HTTP API 文档,特别是关于 render.html
的部分。看起来这正是你想要使用的东西。
你需要对 /render.html
端点进行 GET 请求,并将目标 URL 和 wait
参数作为查询参数传递,例如:
import requests
requests.get('http://localhost:8050/render.html',
params={'url': 'http://www.example.com', 'wait': 2})
如果您想让Splash向目标网站发出POST请求,请使用http_method
和body
参数:
import requests
requests.get('http://localhost:8050/render.html',
params={'url': 'http://httpbin.org/post',
'http_method': 'POST',
'body': 'a=b',
'wait': 2})
/render.html
同时允许向端点发出POST请求:
Splash可以通过HTTP API进行控制。对于下面的所有端点,参数既可以作为GET参数发送,也可以编码为JSON并使用
Content-Type: application/json
头进行POST。
但默认方法仍然是GET。要向目标网站发送POST,仍需要包括http_method
参数:
import requests
requests.post('http://localhost:8050/render.html',
json={'url': 'http://httpbin.org/post',
'http_method': 'POST',
'body': 'a=b',
'wait': 2})
/render.html
提供了http_method
和body
参数。 - paul trmbrth