如何抓取新闻提要?

How to scrape a news feed?

我一直在浏览 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.'>]

我怎样才能找到里面的标签?

当我尝试这个时:

response.xpath('//div')

它 returns 无效。我已经尝试使用 Chome 的 Inspect Elements 来检查内容,但我什至无法访问 body 来尝试一些事情。谢谢

rss 不是 html 文档,它是 xml 文档。您可以在 http://www.w3schools.com/xml/xml_rss.asp 找到有关 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>

所以里面没有div个标签。要获取每个 post/news 的描述,您可以使用 response.xpath('//description/text()')

可以在这里找到 Scrapy 文档 http://doc.scrapy.org/en/latest/intro/tutorial.html