Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python & lxml / xpath: Parsing XML

I need to get the value from the FLVPath from this link : http://www.testpage.com/v2/videoConfigXmlCode.php?pg=video_29746_no_0_extsite

from lxml import html

sub_r = requests.get("http://www.testpage.co/v2/videoConfigXmlCode.php?pg=video_%s_no_0_extsite" % list[6])
sub_root = lxml.html.fromstring(sub_r.content)

for sub_data in sub_root.xpath('//PLAYER_SETTINGS[@Name="FLVPath"]/@Value'):
     print sub_data.text

But no data returned

like image 463
Benabra Avatar asked Apr 09 '26 21:04

Benabra


2 Answers

You're using lxml.html to parse the document, which causes lxml to lowercase all element and attribute names (since that doesn't matter in html), which means you'll have to use:

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

Or as you're parsing a xml file anyway, you could use lxml.etree.

like image 79
mata Avatar answered Apr 11 '26 19:04

mata


You could try

print sub_data.attrib['Value']
like image 28
Tuim Avatar answered Apr 11 '26 18:04

Tuim