scrapy - 如何在 scrapy 中使用 python 请求?

标签 scrapy scrapy-shell

我尝试使用 requests 获取页面,然后将响应对象传递给解析器,但遇到了问题:

def start_requests(self):
    yield self.parse(requests.get(url))
def parse(self, response):
  #pass

builtins.AttributeError: 'generator' object has no attribute 'dont_filter'

最佳答案

您首先需要下载教皇的响应,然后将该字符串转换为 Html Response 对象

from scrapy.http import HtmlResponse
resp = requests.get(url)

response = HtmlResponse(url="", body=resp.text, encoding='utf-8')

关于scrapy - 如何在 scrapy 中使用 python 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56230826/

相关文章:

python - scrapy 需要 Python 2.7 但它已经是

python - splash lua脚本做多次点击访问

web-scraping - 将 url 传递到从 RabbitMQ 使用的 scrapy 中的解析方法

python - 选择器response.xpath和response.css之间的输出差异是什么?

Scrapy Splash 不会执行 lua 脚本

web-scraping - Scrapy shell 与剧作家

python - Scrapy Shell XPath

python - Scrapy 图像管道警告 : File (unknown-error): Error downloading image from <GET

web-scraping - 抓取错误 : 'NotSupported: Unsupported URL scheme ' ': no handler available for that scheme'