我正在抓取一个网站,它包含许多需要从中获取数据的 URL。
我使用 XPath 并获取所有 href
(URL)并保存到列表中。我循环了这个列表并产生了一个请求。下面是我的蜘蛛代码,
class ExampledotcomSpider(BaseSpider):
name = "exampledotcom"
allowed_domains = ["www.example.com"]
start_urls = ["http://www.example.com/movies/city.html"]
def parse(self, response):
hxs = HtmlXPathSelector(response)
cinema_links = hxs.select('//div[@class="contentArea"]/div[@class="leftNav"]/div[@class="cinema"]/div[@class="rc"]/div[@class="il"]/span[@class="bt"]/a/@href').extract()
for cinema_hall in cinema_links:
yield Request(cinema_hall, callback=self.parse_cinema)
def parse_cinema(self, response):
hxs = HtmlXPathSelector(response)
cinemahall_name = hxs.select('//div[@class="companyDetails"]/div[@itemscope=""]/span[@class="srchrslt"]/h1/span/text()').extract()
........
例如,我的列表中有 60 个 URL,大约有 37 个 URL 未下载:对于这些,出现了错误消息:
2012-06-06 14:00:12+0530 [exampledotcom] ERROR: Error downloading <GET http://www.example.com/city/Cinema-Hall-70mm-%3Cnear%3E-place/040PXX40-XX40-000147377847-A6M3>: Error -3 while decompressing: invalid stored block lengths
2012-06-06 14:00:12+0530 [exampledotcom] ERROR: Error downloading <GET http://www.example.com/city/Cinema-Hall-35mm-%3Cnear%3E-place/040PXX40-XX40-000164969686-H9C5>: Error -3 while decompressing: invalid stored block lengths
仅对于某些 URL,Scrapy 正在下载,对于其余的 URL,我不明白发生了什么以及我的代码有什么问题。
有人可以建议我如何消除这些错误吗?
最佳答案
我不认为你的代码有什么问题。
- 解压时出现错误-3:存储的 block 长度无效
- CRC 校验失败 0x471e6e9a != 0x7c07b839L
- 解压时出现错误-3:无效的 block 类型
所有这些错误似乎都与 gzip 解压缩有关。我认为您尝试访问的网站有响应 header Accept-Encoding: gzip, deflate
gzip An encoding format produced by the file compression program "gzip" (GNU zip) as described in RFC 1952 [25]. This format is a Lempel-Ziv coding (LZ77) with a 32 bit CRC.
另请参阅http://en.wikipedia.org/wiki/HTTP_compression
所以我认为这只是一个损坏的网络服务器托管scrapy正在尝试下载的页面。
更新:
关于python - 解压时出现错误-3 : invalid stored block lengths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10911089/