繁体   English   中英

试图在 vscode 调试控制台中执行一个scrapy FormResponse

[英]Trying to execute a scrapy FormResponse but in a vscode debug console

我正在尝试学习如何使用 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()')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM