加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

xpath – 使用scrapy从metatag中提取关键字

发布时间:2020-12-20 12:10:13 所属栏目:Python 来源:网络整理
导读:我正在尝试使用scrapy下载学校项目的一些内容. 我想获得每个页面的关键字列表,然后我可以将其存储在数据库中.这就是我到目前为止所拥有的. scrapy shell http://news.nationalgeographic.com/2015/03/150318-pitcairn-marine-reserve-protected-area-ocean-c
我正在尝试使用scrapy下载学校项目的一些内容.
我想获得每个页面的关键字列表,然后我可以将其存储在数据库中.这就是我到目前为止所拥有的.

scrapy shell http://news.nationalgeographic.com/2015/03/150318-pitcairn-marine-reserve-protected-area-ocean-conservation/

>>> response.xpath('//title/text()').extract()

[u'Worldu2019s 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">'

我想做的只是从meta标签中提取内容,其中name =’keywords’

谢谢!

解决方法

只需添加/ @ content即可提取内容属性:

response.xpath("//meta[@name='keywords']/@content")[0].extract()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读