【问题标题】:Scrapy Missing one Positional Argument ResponseScrapy 缺少一个位置参数响应
【发布时间】:2020-08-01 17:08:52
【问题描述】:

我想将所有链接存储在 my_links 变量中。但是我试图存储的一个他们给了我错误。缺少一个位置参数响应。我是scrapy的新手...请帮助...这是我的代码

import scrapy
from scrapy.crawler import CrawlerProcess


class Udemy_Scraper(scrapy.Spider):
    name = "udemy_scraper"
    start_urls = ['https://couponscorpion.com/']
    def parse(self, response):
        for links in response.xpath('//div[@class="rh-post-wrapper"]'):
            yield {
                'name': links.xpath('.//a/text()').extract(),
            }
    my_links = parse()

提前致谢

【问题讨论】:

    标签: python python-3.x web-scraping scrapy


    【解决方案1】:

    您不需要调用parse 方法,因为它是回调方法,会为start_urls 列表中的所有URL 调用。您可以在蜘蛛级别制作列表。这将起作用。

    import scrapy
    from scrapy.crawler import CrawlerProcess
    
    
    class Udemy_Scraper(scrapy.Spider):
        name = "udemy_scraper"
        my_links = []
        start_urls = ['https://couponscorpion.com/']
        def parse(self, response):
            for links in response.xpath('//div[@class="rh-post-wrapper"]'):
                self.my_links + =[{'name': links.xpath('.//a/text()').extract()}]
            yield self.my_links
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-16
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多