如何提取 <content:encoded> ... </content:encoded>
使用来自 RSS feed 的 scrapy XPath 的内容(下面的示例)?
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Latest – Reason.com</title>
<item>
<pubDate>Thu, 16 Jan 2020 21:40:23 +0000</pubDate>
<content:encoded><![CDATA[<p><span style="font-weight: 400">
Jimmy Meders was scheduled to die by lethal injection today,
but the Georgia parole board has granted him clemency.</span></p>]]>
</content:encoded>
...
我试过了 response.xpath('//content:encoded').get()
, 但它不起作用。
非常感谢任何帮助。
最佳答案
您必须声明并注册一个 XML 命名空间前缀:
response.selector.register_namespace('content',
'http://purl.org/rss/1.0/modules/content/')
response.xpath('//content:encoded').getall()
关于html - 如何将 Scrapy XPath 与 XML 命名空间一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59777994/