我正在尝试学习如何使用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调试控制台中,我会得到一个抓取的请求对象,而不是我需要的响应。我在尝试处理这些请求,而不是在每次想发出调试器时都重新启动调试器。有没有办法做到这一点?
发布于 2021-11-02 10:28:07
请查看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)
https://stackoverflow.com/questions/69803054
复制相似问题