python - 试图在 vscode 调试控制台中执行一个scrapy FormResponse
问题描述
我正在尝试学习如何使用 python scrapy,我想知道是否可以从 vscode 调试控制台手动请求网站。通常我会使用 python 请求和 BeautifulSoup 来获取网站 html,然后我会输入类似
resp = requests.get(website)
直接进入vscode中的调试控制台。从那里我可以在不重新启动调试器的情况下向网站发出更多请求。但是,当我使用scrapy 时,我找不到做同样事情的方法,因为scrapy 请求将被产生/返回。我的请求示例:
yield scrapy.Request(website, callback=self.parse_site})
如果我尝试粘贴scrapy.Request(website ...)
到 vscode 调试控制台,我会得到一个 scrapy 请求对象,而不是我需要的响应。我试图在不重新启动调试器的情况下处理请求,每次我想创建一个。有没有办法做到这一点?
解决方案
检查scrapy shell的文档。
# Either type:
scrapy shell 'https://www.somewebsite.com'
# or:
scrapy shell
# and then create the request and fetch it:
req = scrapy.Request(url='https://www.somewebsite.com')
fetch(req)
# now just get whatever you want from the response, for example:
response.status
response.xpath('//div//text()')
在代码中间打开scrapy shell:
def parse_func(self, response):
from scrapy.shell import inspect_response
inspect_response(response, self)
推荐阅读
- reactjs - 如何键入一个包含 React 组件作为属性以及该组件的道具作为另一个属性的对象?
- reactjs - Heroku 上的 Gatsby 应用程序部署问题
- automated-tests - 如何构建安全回归测试?
- java - Java - RabbitMQ 使用队列中的一些消息
- c# - How to resolve the error InvalidOperationException in Microsoft Visual Studio 2019?
- javascript - 在 React Modal 中追加了多个元素而不是一个
- windows - 当子进程和父进程在 Perl 中写入同一个日志文件时进程卡住(在 Windows 中)
- javascript - 在 React 中设置两个状态变量 onClick
- flutter - 颤振项目添加和删除(芯片)
- javascript - D3 散点图点显示不正确