如何在Python框架Scrapy中解析页面中的RSS链接?

1 投票
1 回答
831 浏览
提问于 2025-04-16 02:00

我想从谷歌搜索中提取信息,并获取每个搜索结果的RSS链接。
我使用的是Scrapy这个工具。
我尝试了这个代码,

...
def parse_second(self, response):
    hxs = HtmlXPathSelector(response)
    qqq = hxs.select('/html/head/link[@type=application/rss+xml]/@href').extract()
    print qqq
    item = response.request.meta['item']
    if len(qqq) > 0:
        item['rss'] = qqq.pop()
    else:
        item['rss'] = ''    
    yield item
...

但是当我执行“print qqq”时,得到了这个结果:

[]

1 个回答

1

发现了一个错误:

qqq = hxs.select("/html/head/link[@type='application/rss+xml']/@href").extract()

这个是可以用的

撰写回答