2012-12-09 115 views

回答

3

您正在使用lxml.html解析文档,这会导致lxml将所有元素和属性名称小写(因为这在html中无关紧要),这意味着您必须使用:

sub_root.xpath('//player_settings[@name="FLVPath"]/@value') 

或者正如你在解析一个xml文件,你可以使用lxml.etree

2

你可以尝试

print sub_data.attrib['Value'] 
+1

它的工作,谢谢:) – Benabra

0
url = "http://www.testpage.com/v2/videoConfigXmlCode.php?pg=video_29746_no_0_extsite" 
response = requests.get(url) 

# Use `lxml.etree` rathern than `lxml.html`, 
# and unicode `response.text` instead of `response.content` 
doc = lxml.etree.fromstring(response.text) 

for path in doc.xpath('//PLAYER_SETTINGS[@Name="FLVPath"]/@Value'): 
    print path