Python 如何获取新闻提要?
我已经阅读了Python 如何获取新闻提要?,python,xpath,scrapy,Python,Xpath,Scrapy,我已经阅读了一些稀奇古怪的示例,它们很有意义,但只要我在新闻提要上尝试一下,我除了标题什么都得不到,也不知道如何继续 scrapy shell http://feeds.bbci.co.uk/news/rss.xml 我能从中得到的只是 response.xpath('//title') 哪个输出 <Selector xpath='//title' data=u'<title xmlns:media="http://search.yahoo.'>] 它返回null。我试着
一些稀奇古怪的
示例,它们很有意义,但只要我在新闻提要上尝试一下,我除了标题什么都得不到,也不知道如何继续
scrapy shell http://feeds.bbci.co.uk/news/rss.xml
我能从中得到的只是
response.xpath('//title')
哪个输出
<Selector xpath='//title' data=u'<title xmlns:media="http://search.yahoo.'>]
它返回null。我试着检查Chome中的元素来检查内容,但不知何故,我甚至无法到达身体去尝试一些东西。谢谢
rss
不是html
文档,它是xml
文档。您可以在rss
上找到相关信息<代码>rss文档看起来像:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>W3Schools Home Page</title>
<link>http://www.w3schools.com</link>
<description>Free web building tutorials</description>
<item>
<title>RSS Tutorial</title>
<link>http://www.w3schools.com/rss</link>
<description>New RSS tutorial on W3Schools</description>
</item>
<item>
<title>XML Tutorial</title>
<link>http://www.w3schools.com/xml</link>
<description>New XML tutorial on W3Schools</description>
</item>
</channel>
</rss>
W3学校主页
http://www.w3schools.com
免费网页建设教程
RSS教程
http://www.w3schools.com/rss
新的学校RSS教程
XML教程
http://www.w3schools.com/xml
关于W3C学校的新XML教程
因此,其中没有div
标记。要获取每篇文章/新闻的描述,可以使用response.xpath('//description/text()')
可以在这里找到刮痧文件你说的“标签”是什么意思?
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>W3Schools Home Page</title>
<link>http://www.w3schools.com</link>
<description>Free web building tutorials</description>
<item>
<title>RSS Tutorial</title>
<link>http://www.w3schools.com/rss</link>
<description>New RSS tutorial on W3Schools</description>
</item>
<item>
<title>XML Tutorial</title>
<link>http://www.w3schools.com/xml</link>
<description>New XML tutorial on W3Schools</description>
</item>
</channel>
</rss>