from wex.extractor import named from wex.etree import xpath, text extract = named(name = xpath('//h1') | text, country = xpath('//dd[@id="country"]') | text, region = xpath('//dd[@id="region"]') | text)
def test_xpath_re_match(): f = (e.xpath('re:match(//body, "\s+is\s+(some)\s+text", "gi")/text()') | list) assert f(create_response(example)) == ['some']
def test_drop_tree(): f = (e.xpath('//*[@id="drop-tree"]') | e.drop_tree(e.css('script')) | e.xpath('string()')) assert f(create_response(example)) == ['Drop this please.']
def test_xpath(): f = e.xpath('//h1/text()') | list assert f(create_response(example)) == ['hi']
def test_xpath_re(): f = e.xpath('//*[re:test(text(), "SOME", "i")]/text()') | list assert f(create_response(example)) == ['some ']
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))
from wex.extractor import named, labelled from wex.iterable import one from wex.etree import xpath, text cheeses = xpath('//h1[@data-icin]') icin_attr = xpath('@data-icin') | one attrs = named(name = text, country = xpath('following::dd[@id="country"][1]') | text, region = xpath('following::dd[@id="region"][1]') | text) extract_cheese = labelled(icin_attr, attrs) def extract(response): for cheese in cheeses(response): for item in extract_cheese(cheese): yield item