【问题标题】:URLs in Scrapy crawler are not yielded to the next parserScrapy 爬虫中的 URL 不会交给下一个解析器
【发布时间】:2013-09-23 01:44:54
【问题描述】:

我在尝试爬取http://www.brand-in-trend.ru 时遇到了一个屈服问题。正如您在下面看到的,我正在使用 Scrapy 并定义了一个 Basespider。第一个解析器工作得很好,并返回在 start_url 上找到的所有品牌。

现在,当我想向类别解析器产生回调请求时,我没有收到响应或错误。蜘蛛就退出了。

蜘蛛:

class brandintrend(BaseSpider):
name = "brandintrend"

allowed_domains = [ 'trend-in-brand.ru' ]

start_urls      = [ 'http://brand-in-trend.ru/brands/' ]

def parse(self, response):
    hxs         = HtmlXPathSelector(response)
    brands      = hxs.select('//div[@class="brandcol"]/ul/li/a/@href').extract()

    for brand in brands:
        brand = "http://www.brand-in-trend.ru" + brand
        print brand
        # request = Request(brand, callback=self.categories)
        yield Request(brand, callback=self.categories)

def categories(self, response):
    print "Hello World"
    hxs = HtmlXPathSelector(response)
    print response.url

我已经尝试了以下方法来解决这个问题:

  1. 我在 Chrome 中测试了生成的品牌网址(例如 http://www.brand-in-trend.ru/brands/parker/)(Javasript 已关闭),它们运行良好。
  2. 我将所有生成的品牌网址放在 start_url 列表中,并尝试将它们直接提供给类别解析器
  3. 我看了这篇文章,很遗憾没有解决我的问题:scrapy unable to make Request() callback

如果有人遇到类似的问题,我会很高兴提供解决方案或建议

提前致谢

J

【问题讨论】:

    标签: python scrapy yield


    【解决方案1】:

    这是因为你设置了:

    allowed_domains = [ 'trend-in-brand.ru' ]
    

    但是,您正在从不同的域抓取 url:

    start_urls = [ 'http://brand-in-trend.ru/brands/' ]
    

    参见trend-in-brandbrand-in-trend

    【讨论】:

    • 现在,我也看到了。这是一个咬指甲,但如此简单
    • @KangLi 好的,然后考虑accepting the answer,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    相关资源
    最近更新 更多