2012-12-09 169 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