def extract(response): tree = parse(response) return text(tree.xpath('//h1/text()'))
def test_text_html_comment(): tree = html.fromstring('<html><!-- comment --></html>') assert [t for t in e.text(tree)] == []
def extract(response): tree = parse(response) yield "name", text(tree.xpath('//h1/text()')) yield "whoops", 1/0 yield "country", text(tree.xpath('//dd[@id="country"]')) yield "region", text(tree.xpath('//dd[@id="region"]'))
def region(response): return text(xpath('//dd[@id="region"]')(response))
def name(response): return text(xpath('//h1')(response))
def country(response): return text(xpath('//dd[@id="country"]')(response))