Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取新闻提要?_Python_Xpath_Scrapy - Fatal编程技术网

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>