Beispiel #1
1
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)
Beispiel #2
0
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']
Beispiel #3
0
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.']
Beispiel #4
0
def test_xpath():
    f = e.xpath('//h1/text()') | list
    assert f(create_response(example)) == ['hi']
Beispiel #5
0
def test_xpath_re():
    f = e.xpath('//*[re:test(text(), "SOME", "i")]/text()') | list
    assert f(create_response(example)) == ['some ']
Beispiel #6
0
def region(response):
    return text(xpath('//dd[@id="region"]')(response))
Beispiel #7
0
def name(response):
    return text(xpath('//h1')(response))
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.']
Beispiel #9
0
def country(response):
    return text(xpath('//dd[@id="country"]')(response))
Beispiel #10
0
def test_xpath_re():
    f = e.xpath('//*[re:test(text(), "SOME", "i")]/text()') | list
    assert f(create_response(example)) == ['some ']
Beispiel #11
0
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']
Beispiel #12
0
def test_xpath():
    f = e.xpath('//h1/text()') | list
    assert f(create_response(example)) == ['hi']
Beispiel #13
0
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
Beispiel #14
0
def name(response):
    return text(xpath('//h1')(response))
Beispiel #15
0
def region(response):
    return text(xpath('//dd[@id="region"]')(response))
Beispiel #16
0
def country(response):
    return text(xpath('//dd[@id="country"]')(response))