我对Python非常陌生。我想在python中通过scrapy发送一个http请求,并在一个变量中获得响应。我不知道如何捕捉回复文本。
from scrapy import Request
url = '***'
headers = {
"authority": "***",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36",
"x-requested-with": "XMLHttpRequest",
"authorization": "BasicAuthentication ***",
"content-type": "application/json",
"accept": "*/*",
"origin": "***",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "***",
"accept-language": "en-US,en;q=0.9,fa;q=0.8,tr;q=0.7"
}
body = '***'
request = Request(
url=url,
method='POST',
dont_filter=True,
headers=headers,
body=body,
)发布于 2020-09-05 00:23:17
为了让scrapy发出请求,您需要创建一个爬虫项目或爬虫进程。Scrapy将启动其他几个进程来执行请求,因此它似乎不是您所需的最佳选择。你可以对scrapy是如何工作的here有一个概述。
如果您的意图只是在python代码中间发出一个请求,并使用的响应,我建议您使用requests library。
如果您想了解有关scrapy的更多信息,请从tutorial开始。
https://stackoverflow.com/questions/63743719
复制相似问题