I am trying to get the HTML content of child node with lxml and xpath in Python. As shown in code below, I want to find the html content of the each of product nodes. Does it have any methods like product.html?
productGrids = tree.xpath("//div[@class='name']/parent::*")
for product in productGrids:
print #html content of product
I believe you want to use the
tostring()
method:another way to do this
After right clicking (copy, copy xpath) on the specific field you want (in chrome's inspector), you might get something like this:
If you wanted that text element for each "specialID"
You could select another field and it'll interleave the results
Example could be improved, but it illustrates the point:
you may see more examples here: http://lxml.de/tutorial.html
Simple function to get innerHTML or innerXML
.
Try it out directly https://pyfiddle.io/fiddle/631aa049-2785-4c58-bf82-eff4e2f8bedb/
.
function
invocation
.
Logic Behind
tostring
You can use
product.text_content()