Jan-29-2017, 01:35 AM
I was thinking more of xpath method, something like an alternative to BeautifulSoup side by side
from lxml import etree from bs4 import BeautifulSoup html = '<html><head><title>foo</title></head><body><div class="other"></div><div class="name"><p>foo</p></div><div class="name"><ul><li>bar</li></ul></div></body></html>' tree = etree.fromstring(html) for elem in tree.xpath("//div[@class='name']"): print(etree.tostring(elem, pretty_print=True)) soup = BeautifulSoup(html, 'lxml') for elem in soup.find_all('div', {'class':'name'}): print(elem.prettify())
Recommended Tutorials: