使用 scrapy 从 metatag 中提取关键字
Extracting keywords from metatag using scrapy
我正在尝试使用 scrapy 为学校项目下载一些内容。
我想获取每个页面的关键字列表,然后我可以将其存储在数据库中。这就是我到目前为止所得到的。
scrapy shell http://news.nationalgeographic.com/2015/03/150318-pitcairn-marine-reserve-protected-area-ocean-conservation/
>>> response.xpath('//title/text()').extract()
[u'World\u2019s Largest Single Marine Reserve Created in Pacific']
>>> response.xpath("//meta[@name='keywords']")[0].extract()
u'<meta name="keywords" content="ocean life, conservationists, marine biodiversity, marine sanctuaries, wildlife conservation, marine protected areas, mpas, reserves, sanctuaries, ocean conservation">'
我想做的只是从 name='keywords'
的元标记中提取内容
谢谢!
只需添加/@content
即可提取content
属性:
response.xpath("//meta[@name='keywords']/@content")[0].extract()
我正在尝试使用 scrapy 为学校项目下载一些内容。 我想获取每个页面的关键字列表,然后我可以将其存储在数据库中。这就是我到目前为止所得到的。
scrapy shell http://news.nationalgeographic.com/2015/03/150318-pitcairn-marine-reserve-protected-area-ocean-conservation/
>>> response.xpath('//title/text()').extract()
[u'World\u2019s Largest Single Marine Reserve Created in Pacific']
>>> response.xpath("//meta[@name='keywords']")[0].extract()
u'<meta name="keywords" content="ocean life, conservationists, marine biodiversity, marine sanctuaries, wildlife conservation, marine protected areas, mpas, reserves, sanctuaries, ocean conservation">'
我想做的只是从 name='keywords'
的元标记中提取内容谢谢!
只需添加/@content
即可提取content
属性:
response.xpath("//meta[@name='keywords']/@content")[0].extract()