请求不允许从响应获取状态代码的url

2024-04-24 16:37:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一个解决方案,提出一个不允许的域检查出站链接的请求。在

但我的函数“parse_outboundLinks”从未被调用。在

我必须修改允许的域?在

谢谢你的帮助

我的代码:

    name = "mySpider"
    allowed_domains = ["monsite.fr"]
    start_urls = ["http://www.monsite.fr/"]
    rules = [Rule(SgmlLinkExtractor(allow=()),follow='true',callback='parse_item')]

    def parse_item(self, response):
        xlink = SgmlLinkExtractor(deny_domains=(self.allowed_domains[0]))
        for link in xlink.extract_links(response):
            Request(link.url, callback=self.parse_outboundLinks)

   def parse_outboundLinks(self, response):
         print response.status

Tags: selfparseresponsedefcallbacklinkfr解决方案
1条回答
网友
1楼 · 发布于 2024-04-24 16:37:52

只有在指定了yield时,才会调用Parse函数。
Request(link.url, callback=self.parse_outboundLinks)更改为yield Request(link.url, callback=self.parse_outboundLinks)

其他线程也存在类似问题。
scrapy's Request function is not being called

相关问题 更多 >