0

我正在尝试找出一种方法来使用 python 读取 URL 内容,然后将标题解析为变量。

显示/读取的 URL 数据示例:

<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" debug="true">
    <script id="FirebugLite" firebugIgnore="true" extension="Chrome"/>
    <song id="11450" parent="11042" title="30 Minutes Or Less (2011)" album="30 Minutes Or Less (2011)" isDir="false" created="2011-11-04T16:07:38" duration="4983" bitRate="1536" size="3521040154" suffix="mkv" contentType="video/x-matroska" isVideo="true" path="30 Minutes Or Less (2011)/30 Minutes Or Less (2011).mkv" transcodedSuffix="flv" transcodedContentType="video/x-flv"/>
</subsonic-response>

有没有办法从标题字段中获取数据?所以在一个变量中,我最终会得到“30 分钟或更少(2011 年)”

我现在有流动的代码,但很难让它工作。

import urllib, urllib2
from xml.etree.ElementTree import ElementTree
url = 'https://myurl.com'
root = urllib.urlopen(url).read()
tester = ElementTree.parse(root)
elem = ElementTree.find("title")
print elem

错误:TypeError:必须使用 ElementTree 实例作为第一个参数调用未绑定的方法 parse()(改为获取 str 实例)

4

0 回答 0