//div[contains(@class, 'class1') and contains(@class, 'class2')]
>>> import lxml.html
>>> html = lxml.html.fromstring('''\
... <html><body onload="" color="white">
... <p>Hi !</p>
... </body></html>
... ''')
>>> print lxml.html.tostring(html)
<html><body onload="" color="white"><p>Hi !</p></body></html>
>>> print lxml.html.tostring(html)
<html> <body color="white" onload=""> <p>Hi !</p> </body> </html>
>>> print lxml.html.tostring(html)
<html>
<body color="white" onload="">
<p>Hi !</p>
</body>
</html>
>>> etree.strip_tags(fragment,'a','c')
>>> etree.tostring(fragment)
'<fragment>text1 inner1 text2 <b>inner2</b> text3</fragment>'
from lxml import etree
tree = etree.fromstring('<html><head><title>foo</title></head><body><div class="name"><p>foo</p></div><div class="name"><ul><li>bar</li></ul></div></body></html>')
for elem in tree.xpath("//div[@class='name']"):
# pretty_print ensures that it is nicely formatted.
print etree.tostring(elem, pretty_print=True)
from lxml import etree, html
tree = html.parse('http://rutracker.org/forum/index.php')
for elem in tree.xpath("//div[@class='category']"):
print html.tostring(elem, pretty_print=True)
from StringIO import StringIO
from lxml import etree, html
import requests
c = requests.get('http://rutracker.org/forum/index.php').content
tree = html.parse(StringIO(s))
for elem in tree.xpath("//div[@class='category']"):
print html.tostring(elem, pretty_print=True)
Что не так я делаю?работаешь с xml как с html
from lxml import etree
tree = etree.parse('http://xml.weather.yahoo.com/forecastrss/RSXX0091_c.xml')
print tree.xpath('//description/text()')[0]
// Yahoo! Weather for Saint Petersburg, RS