如何在Python框架Scrapy中从页面解析RSS链接(获取URL到RSS)?

时间:2010-07-29 11:50:47

标签: python xpath rss parsing scrapy

我想解析Google搜索,并从搜索结果中的每个项目获取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 个答案:

答案 0 :(得分:1)

发现错误:

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

有效