コード例 #1
0
ファイル: test_html_text.py プロジェクト: cslovell/html-text
def test_selectors(all_options):
    html = (u'<span><span id="extract-me">text<a>more</a>'
            '</span>and more text <a> and some more</a> <a></a> </span>')
    # Selector
    sel = cleaned_selector(html)
    assert selector_to_text(
        sel, **all_options) == 'text more and more text and some more'

    # SelectorList
    subsel = sel.xpath('//span[@id="extract-me"]')
    assert selector_to_text(subsel, **all_options) == 'text more'
    subsel = sel.xpath('//a')
    assert selector_to_text(subsel, **all_options) == 'more and some more'
    subsel = sel.xpath('//a[@id="extract-me"]')
    assert selector_to_text(subsel, **all_options) == ''
    subsel = sel.xpath('//foo')
    assert selector_to_text(subsel, **all_options) == ''
コード例 #2
0
def test_selector(all_options):
    html = '<div><div id="extract-me">text<div>more</div></div>and more text</div>'
    sel = cleaned_selector(html)
    assert selector_to_text(sel, **all_options) == 'text more and more text'
    subsel = sel.xpath('//div[@id="extract-me"]')[0]
    assert selector_to_text(subsel, **all_options) == 'text more'