【问题标题】:scrapy.exceptions.NotSupported: Unsupported URL scheme '': no handler available for that schemescrapy.exceptions.NotSupported:不支持的 URL 方案“”:该方案没有可用的处理程序
【发布时间】:2019-07-09 18:24:09
【问题描述】:

我从几个目录中收集链接,然后将它们作为链接变量插入到 start_urls 中

import scrapy


class SplashSpider(scrapy.Spider):
    f = open('text.txt')
    links = f.read()
    name = 'spide'
    start_urls = [str(links)]
    f.close()

    def parse(self, response):
        title = response.css('.title::text').extract()
        description = response.css("div#desc").extract()
        title = list(map(str.strip, title))
        description = list(map(str.strip, description))
        yield{
            'Title': title,
            'Main Info': description,
        }

但我发现一个错误:scrapy.exceptions.NotSupported: Unsupported URL scheme '': no handler available for that scheme

我的 text.txt 文件:

'https:// url1.com','https:// url2.com', ... , 'https:// url300000.com', 'https:// url300001.com'

【问题讨论】:

  • 在您的文本文件中看起来像一个空白行。

标签: scrapy


【解决方案1】:
import scrapy


class SplashSpider(scrapy.Spider):
    with open('text.txt') as f:
        links = f.readlines()
        links = list(map(lambda x: x.strip().replace(' ', ''), links))
    name = 'spider'
    start_urls = links

    def parse(self, response):
        title = response.css('.title::text').extract()
        description = response.css("div#desc").extract()
        title = list(map(str.strip, title))
        description = list(map(str.strip, description))
        yield{
            'Title': title,
            'Main Info': description,
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多