我有一个中间件,如果URL包含“ https”,它将[提高IgnoreRequests()]。
class MiddlewareSkipHTTPS(object):
def process_response(self, request, response, spider):
if (response.url.find("https") > -1):
raise IgnoreRequest()
else:
return response
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以完全防止scrapy对HTTPS URL执行GET请求?没有[IgnoreRequests()]及其代码段,我得到的response_bytes / response_count值相同。我正在寻找零值,并跳过抓取网址。我不希望scrapy爬网/下载https页面中的所有字节,只需转到下一个URL。
注意:必须是中间件,不想使用Spider中嵌入的规则。有数百只蜘蛛,想要巩固逻辑。
不要使用process_response,它已在发出请求后被调用。
您需要使用
def process_request(request, spider):
request.url # URL being scraped
Run Code Online (Sandbox Code Playgroud)
在实际发出请求之前调用此方法。
看这里