[Python] Signature of method 'myspider. parse()' does not match signature of the base method...

Discussão em 'Python' iniciado por Stack, Novembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to scrape a webpage (https://a-z-animals.com/animals/) to get all the animal names listed there.

    I installed scrapy in my PyCharm project. Then, by using the terminal in PyCharm, created a folder using scrapy startproject AnimalNames. I navigated into that folder and created a spider using scrapy genspider animals https://a-z-animals.com/animals/

    Then I added to the code in animals.py, which is meant to retrieve the animal names from the site:

    import scrapy


    class AnimalsSpider(scrapy.Spider):
    name = "animals"
    allowed_domains = ["a-z-animals.com"]
    start_urls = ["https://a-z-animals.com/animals/"]

    def parse(self, response):
    for container in response.css('div.container'):
    yield {
    container.css('a::text').get()
    }


    But PyCharm underlines the parse method parameters ((self, response)) and tells me:


    Signature of method AnimalsSpider.parse() does not match signature of the base method in class Spider
    ​

    When I run the spider using scrapy crawl animals -O names_of_animals.json it just gives me an empty json file.

    How do I fix this so it makes me a json file of all the animal names in the site?

    Note that I had to change the USER_AGENT and DOWNLOAD_DELAY in settings.py so the webpage doesn't block me.

    Continue reading...

Compartilhe esta Página