def demo5(): text = """ <html> <table> <tr><td>http://google.ca</td></tr> <tr><td>http://reddit.com</td></tr> </table> </html> """ doc = lx.to_doc(text) lx.show_paths(doc)
def test_show_paths(): doc = lx.to_doc(ex.HTML_1) old_stdout = sys.stdout buf = StringIO() sys.stdout = buf # lx.show_paths(doc, find=None) assert "'Want This' => /html/body/table/tr[2]/td" in buf.getvalue() # buf = StringIO() sys.stdout = buf lx.show_paths(doc, find='Google.ca') assert "'Google.ca' => /html/body/a" in buf.getvalue() # buf.close() sys.stdout = old_stdout
def demo7(): text = """<html> <body <div></div> <div id="content"> <ul> <li>First item</li> <li>Second item</li> </ul> </div> </body> </html>""" doc = lx.to_doc(text) lx.show_paths(doc) for tag in doc.cssselect("div#content ul li"): print tag.text print lx.css_to_xpath("div#content ul li") lx.open_in_browser(doc)