Skip to content Skip to sidebar Skip to footer

How Do I Fix Scrapy Unsupported URL Scheme Error?

I collect url from command python and then insert it into start_urls from flask import Flask, jsonify, request import scrapy import subprocess class ClassSpider(scrapy.Spider):

Solution 1:

I guess this happens because you first append url to self.start_urls and then you call ClassSpiders run method with your list self.start_urls which in turn appends the list to a list and you end up with a nested list instead of a list of strings.
To avoid this you should maybe change your __init__ method like this:

    def __init__(self, url, nbrPage):
        self.pages      = nbrPage
        self.url        = url
        self.start_urls = []
        self.start_urls.append(url)

And then pass self.url instead of self.start_urls in run:

    def run(self):
        subprocess.check_output(['scrapy', 'crawl', 'mySpider', '-a', f'url={self.url}', '-a', f'nbrPage={self.pages}'])
        return self.news

Post a Comment for "How Do I Fix Scrapy Unsupported URL Scheme Error?"