使用Scrapy爬网本地XML文件 - 启动URL本地文件地址

say*_*yth 2 python xml xpath scrapy scrapy-spider

我想使用scrapy抓取我在Downloads文件夹中找到的本地xml文件,使用xpath提取相关信息.

使用scrapy介绍作为指导

2016-01-24 12:38:53 [scrapy] DEBUG: Retrying <GET file://home/sayth/Downloads/20160123RAND0.xml> (failed 2 times): [Errno 2] No such file or directory: '/sayth/Downloads/20160123RAND0.xml'
2016-01-24 12:38:53 [scrapy] DEBUG: Gave up retrying <GET file://home/sayth/Downloads/20160123RAND0.xml> (failed 3 times): [Errno 2] No such file or directory: '/sayth/Downloads/20160123RAND0.xml'
2016-01-24 12:38:53 [scrapy] ERROR: Error downloading <GET file://home/sayth/Downloads/20160123RAND0.xml>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了下面的几个版本但是我无法获得启动URL接受我的文件.

# -*- coding: utf-8 -*-
import scrapy


class MyxmlSpider(scrapy.Spider):
    name = "myxml"
    allowed_domains = ["file://home/sayth/Downloads"]
    start_urls = (
        'http://www.file://home/sayth/Downloads/20160123RAND0.xml',
    )

    def parse(self, response):
        for file in response.xpath('//meeting'):
            full_url = response.urljoin(href.extract())
            yield scrapy.Request(full_url, callback=self.parse_question)

    def parse_xml(self, response):
        yield {
            'name': response.xpath('//meeting/race').extract()
        }
Run Code Online (Sandbox Code Playgroud)

只是为了确认我确实在那个位置有文件

sayth@sayth-HP-EliteBook-2560p : ~/Downloads
[0] % ls -a
.                                                              Building a Responsive Website with Bootstrap [Video].zip
..                                                             codemirror.zip
1.1 Situation Of Long Term Gain.xls                            Complete-Python-Bootcamp-master.zip
2008 Racedata.xls                                              Cox Plate 2005.xls
20160123RAND0.xml  
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 7

在协议之后根本不指定allowed_domains并使用3个斜杠:

start_urls = ["file:///home/sayth/Downloads/20160123RAND0.xml"]
Run Code Online (Sandbox Code Playgroud)