如何在scrapy中使用python请求?

编程入门 行业动态 更新时间:2024-10-28 10:36:23
本文介绍了如何在scrapy中使用python请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

def start_requests(self):产量 self.parse(requests.get(url))定义解析(自我,响应):#经过

builtins.AttributeError: 'generator' 对象没有属性 'dont_filter'

解决方案

您首先需要下载页面的响应,然后将该字符串转换为 HtmlResponse 对象

from scrapy.http import HtmlResponseresp = requests.get(url)response = HtmlResponse(url="", body=resp.text, encoding='utf-8')

I am trying to use requests to fetch a page then pass the response object to a parser, but I ran into a problem:

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

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

解决方案

You first need to download the page's resopnse and then convert that string to HtmlResponse object

from scrapy.http import HtmlResponse resp = requests.get(url) response = HtmlResponse(url="", body=resp.text, encoding='utf-8')

更多推荐

如何在scrapy中使用python请求?

本文发布于:2023-11-23 09:24:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   scrapy   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!