我正在尝试使用以下格式获取一个xml文件
文件_示例.xml:
<rss version="2.0">
<channel>
<item>
<title>SENIOR BUDGET ANALYST (new)</title>
<link>https://hr.example.org/psp/hrapp&SeqId=1</link>
<pubDate>Wed, 18 Jul 2012 04:00:00 GMT</pubDate>
<category>All Open Jobs</category>
</item>
<item>
<title>BUDGET ANALYST (healthcare)</title>
<link>https://hr.example.org/psp/hrapp&SeqId=2</link>
<pubDate>Wed, 18 Jul 2012 04:00:00 GMT</pubDate>
<category>All category</category>
</item>
</channel>
</rss>
以下是我的蜘蛛网.py代码
^{pr2}$结果:
2012-07-25 13:24:14+0530 [testproject] DEBUG: Scraped from <200 https://hr.templehealth.org/hrapp/rss/careers_jo_rss.xml>
{'title': [u'SENIOR BUDGET ANALYST (hospital/healthcare)',
u'BUDGET ANALYST'],
'link': [u'https://hr.example.org/psp/hrapp&SeqId=1',
u'https://hr.example.org/psp/hrapp&SeqId=2']
'pubdate': [u'Wed, 18 Jul 2012 04:00:00 GMT',
u'Wed, 18 Jul 2012 04:00:00 GMT']
'category': [u'All Open Jobs',
u'All category']
}
从上面的结果可以看出,所有来自相应标记的结果都被组合到一个列表中,但是我想根据它们的单个项标记进行映射,如下所示,就像我们为html抓取所做的那样。在
{'title': u'SENIOR BUDGET ANALYST (hospital/healthcare)'
'link': u'https://hr.example.org/psp/hrapp&SeqId=1'
'pubdate': u'Wed, 18 Jul 2012 04:00:00 GMT'
'category': u'All Open Jobs'
}
{'title': u'BUDGET ANALYST'
'link': u'https://hr.example.org/psp/hrapp&SeqId=2'
'pubdate': u'Wed, 18 Jul 2012 04:00:00 GMT'
'category': u'All category'
}
我们如何根据单独的主标记(如上面的item标记)来获取xml标记数据。在
提前谢谢。。。。。。。。。。。。。在
尝试将您的itertag从
itertag = 'channel'
更改为'itertag = 'item'
只需更改itertag='item'。在
如果您参考parse_node方法的文档,则说明该方法是为与所提供的标记名(itertag)匹配的节点调用的。如果是“item”(子节点到“channel”rootnode)。在
我建议使用feedparser:
结果
^{pr2}$相关问题 更多 >
编程相关推荐