首页 文章

Scrapy Middleware忽略URL并阻止抓取

提问于
浏览
2

如果url包含“https”,我有一个[引发IgnoreRequests()]的中间件 .

class MiddlewareSkipHTTPS(object):
    def process_response(self, request, response, spider):
        if (response.url.find("https") > -1):
            raise IgnoreRequest()
        else:
            return response

enter image description here

有没有办法完全阻止scrapy对HTTPS网址执行GET请求?我在没有[IgnoreRequests()]的情况下获得了response_bytes / response_count的相同值,并使用了我的代码片段 . 我正在寻找零值并跳过抓取网址 . 我不希望scrapy从https页面爬行/下载所有字节,只需转到下一个URL .

注意:必须是中间件,不要使用嵌入蜘蛛的规则 . 有数百个蜘蛛,并希望巩固逻辑 .

2 回答

相关问题