繁体   English   中英

使用elementtree解析xml网站

[英]parsing xml site using elementtree

import elementtree.ElementTree as ET
import urllib  

name = name.lower().replace(' ','%20')
id_search = 'http://services.tvrage.com/myfeeds/search.php?key=ag6txjP0RH4m0c8sZk2j&show='+name
tree = ET.parse(urllib.urlopen(id_search))
root = tree.getroot()
showid = root.find('showid')
url = 'http://services.tvrage.com/myfeeds/episode_list.php?key=ag6txjP0RH4m0c8sZk2j&sid='+str(showid)

由于某种原因, showid不会显示出来。 任何帮助都会很棒。 我在xbmc插件上使用它来刮除showid。

这是链接http://services.tvrage.com/myfeeds/search.php?key=ag6txjP0RH4m0c8sZk2j&show=black%20sails

xml文件的根元素是results -element,仅包含show -elements。 您试图从results获取subelement show-id ,而show-id -elements都是show子元素。

您可以使用showid = root.find('show/show-id') ,但是您可能希望使用for循环和findall-function而不是find-function。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM