【问题标题】:scrapy not following links with no errorscrapy没有跟随没有错误的链接
【发布时间】:2018-05-30 12:51:37
【问题描述】:

下面的url都是用来提取内容和被关注的,但是提取内容之后什么都没有发生。不知道为什么没有遵循。

似乎没有错误。

【问题讨论】:

    标签: python callback request scrapy-spider


    【解决方案1】:

    您两次运行作者网址的请求。第一次刮作者名单。第二次抓取当前作者的详细信息。转储 Scrapy 统计信息(在记录结束时)显示“dupefilter/filtered”计数。这意味着scrapy过滤了重复的URL。如果您删除“parse_content”函数并编写如下代码,则抓取将起作用:

    def parse(self,response):
    
        if 'tags' in response.meta:
            author = {}
            author['url'] = response.url
    
            name = response.css(".people-name::text").extract()
            join_date = response.css(".joined-time::text").extract()
            following_no = response.css(".following-number::text").extract()
            followed_no = response.css(".followed-number::text").extract_first()
            first_onsale = response.css(".first-onsale-date::text").extract()
            total_no = response.css(".total-number::text").extract()
            comments = total_no[0]
            onsale = total_no[1]
            columns = total_no[2]
            ebooks = total_no[3]
            essays = total_no[4]
    
            author['tags'] = response.meta['tags']
            author['name'] = name
            author['join_date'] = join_date
            author['following_no'] = following_no
            author['followed_no'] = followed_no
            author['first_onsale'] = first_onsale
            author['comments'] = comments
            author['onsale'] = onsale
            author['columns'] = columns
            author['ebooks'] = ebooks
            author['essays'] = essays
    
            yield author
    
        authors = response.css('section.following-agents ul.bd li.item')
        for author in authors:
            tags = author.css('div.author-tags::text').extract_first()
            url = author.css('a.lnk-avatar::attr(href)').extract_first()
            yield response.follow(url=url, callback=self.parse, meta={'tags': tags})
    

    小心点。我在测试期间删除了一些行。您需要在 HTTP 标头、请求延迟或代理中使用随机代理。我运行收集,现在我得到“403 Forbidden”状态码。

    【讨论】:

    • 感谢您的回答。但在这种情况下,作者 [“tag”] 是从作者列表中提取的,这就是我使用 request.meta 的原因。我真的需要这个标签属性。
    猜你喜欢
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 2014-02-25
    • 2020-09-06
    相关资源
    最近更新 更多