python - 请求 URL 中缺少方案

标签 python url scrapy

在这个bug上卡了一段时间,下面的错误信息如下:

File "C:\Python27\lib\site-packages\scrapy-0.20.2-py2.7.egg\scrapy\http\request\__init__.py", line 61, in _set_url
            raise ValueError('Missing scheme in request url: %s' % self._url)
            exceptions.ValueError: Missing scheme in request url: h

抓取代码:

    from scrapy.contrib.spiders import CrawlSpider, Rule
    from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
    from scrapy.selector import Selector
    from scrapy.http import Request
    from spyder.items import SypderItem

    import sys
    import MySQLdb
    import hashlib
    from scrapy import signals
    from scrapy.xlib.pydispatch import dispatcher

    # _*_ coding: utf-8 _*_

    class some_Spyder(CrawlSpider):
        name = "spyder"

        def __init__(self, *a, **kw):
            # catch the spider stopping
            # dispatcher.connect(self.spider_closed, signals.spider_closed)
            # dispatcher.connect(self.on_engine_stopped, signals.engine_stopped)

            self.allowed_domains = "domainname.com"
            self.start_urls = "http://www.domainname.com/"
            self.xpaths = '''//td[@class="CatBg" and @width="25%" 
                          and @valign="top" and @align="center"]
                          /table[@cellspacing="0"]//tr/td/a/@href'''

            self.rules = (
                Rule(SgmlLinkExtractor(restrict_xpaths=(self.xpaths))),
                Rule(SgmlLinkExtractor(allow=('cart.php?')), callback='parse_items'),
                )

            super(spyder, self).__init__(*a, **kw)

        def parse_items(self, response):
            sel = Selector(response)
            items = []
            listings = sel.xpath('//*[@id="tabContent"]/table/tr')

            item = IgeItem()
            item["header"] = sel.xpath('//td[@valign="center"]/h1/text()')

            items.append(item)
            return items

我很确定这与我要求 scrapy 在 LinkExtractor 中跟踪的 URL 有关。在 shell 中提取它们时,它们看起来像这样:

data=u'cart.php?target=category&category_id=826'

与从工作蜘蛛中提取的另一个 URL 相比:

data=u'/path/someotherpath/category.php?query=someval'

我看过一些关于 Stack Overflow 的问题,例如 Downloading pictures with scrapy但从阅读中我想我可能有一个稍微不同的问题。

我也看过这个 - http://static.scrapy.org/coverage-report/scrapy_http_request___init__.html

这解释了如果 self.URLs 缺少“:”则会引发错误,通过查看我定义的 start_urls 我不太明白为什么会显示此错误,因为该方案已明确定义。

最佳答案

start_urls 更改为:

self.start_urls = ["http://www.bankofwow.com/"]

关于python - 请求 URL 中缺少方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21103533/

相关文章:

python - 获取 ElastiCache 标签

python - 加速 Python While 循环

php - Codeigniter URI 类我如何使用 – 连字符而不是 _ 下划线?

javascript - 如何监听url的变化(Fragment identifier - the anchor part of a URL)

python - 类型错误 : takes exactly 1 argument (0 given) - Scrapy

python - IF 语句 Pandas Dataframe : The truth value of a Series is ambiguous

python - 如何将字典写入现有文件?

javascript - 解析一个URL(作为字符串)并将每个子页面拼接成一个数组

python - 按 "pip install --upgrade"升级 pip 和 scrapy 后出现 pip 错误

exception - scrapy未处理的异常