2023-07-07 144817 scrapycorescraper ERROR Spider error processing GET httpsnews163comworld referer httpsnews163comTraceback most recent call last File GpythonAnacondalibsite-packagesscrapyutilsdeferp
这个错误是由于在发送请求时,URL缺少了协议头(scheme)导致的。在你的代码中,报错的地方是在parse_model方法中发送请求时,new_url参数没有包含协议头。
要解决这个问题,你需要确保new_url参数包含正确的协议头,例如http://或https://。你可以在构造new_url参数时,手动添加协议头,或者使用urljoin函数来自动添加。
下面是一个示例,演示如何使用urljoin函数来添加协议头:
from urllib.parse import urljoin
# ...
def parse_model(self, response):
# ...
# 使用urljoin函数添加协议头
new_url = urljoin(response.url, relative_url)
yield scrapy.Request(url=new_url, callback=self.new_detail, meta={'item': item})
原文地址: https://www.cveoy.top/t/topic/hQEu 著作权归作者所有。请勿转载和采集!