Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Scrapy-SGMLLinkedExtractor除了传递href外,还传递href文本以处理_值回调_Python_Python 2.7_Scrapy - Fatal编程技术网

Python Scrapy-SGMLLinkedExtractor除了传递href外,还传递href文本以处理_值回调

Python Scrapy-SGMLLinkedExtractor除了传递href外,还传递href文本以处理_值回调,python,python-2.7,scrapy,Python,Python 2.7,Scrapy,我想添加对不包含我要查找的单词但href文本确实包含的链接的支持 我希望能够提取href文本,并将其作为第二个参数传递给process_value callback 有人知道如何实现这些目标吗 谢谢。你应该创建一个BaseSpider并根据你想要的任何条件提取链接 给你一个想法: class MySpider(BaseSpider): def parse(self, response): hxs = HtmlXPathSelector(response)

我想添加对不包含我要查找的单词但href文本确实包含的链接的支持

我希望能够提取href文本,并将其作为第二个参数传递给process_value callback

有人知道如何实现这些目标吗


谢谢。

你应该创建一个BaseSpider并根据你想要的任何条件提取链接

给你一个想法:

class MySpider(BaseSpider):

    def parse(self, response):
        hxs = HtmlXPathSelector(response)
        links = hxs.select('//a')
        for link in links:
            href = link.select('@href').extract()[0]
            text = links.select('text()').extract()[0]
                # I make an assumption here that you want text() instead of @href here
                if text == 'something':
                        yield Request(href, callback = self.parse_page)

    def parse_page(self, response):
        return #return your item here

我的刮刀正在使用SGMLLinkedExtractor。我想添加一个选项,将href文本传递给process_值回调函数。没有主意吗?修补SGMLLinkedExtractor以提取href文本是否容易?我确信要使用另一个刮刀来实现此目标,因此我接受此解决方案。10倍