コード例 #1
0
def test_attr_field_with_default_and_many():
    field = AttrField(css_select="div.brand b",
                      attr="href",
                      default="nothing",
                      many=True)
    values = field.extract(html_etree=html_etree)
    assert values == ["nothing"]
コード例 #2
0
def test_attr_field_with_default():
    field = AttrField(css_select="div.brand b", attr="href", default="nothing")
    value = field.extract(html_etree=html_etree)
    assert value == "nothing"
コード例 #3
0
def test_attr_field_many():
    field = AttrField(css_select="a.test_link", attr="href", many=True)
    values = field.extract(html_etree=html_etree)
    assert len(values) == 5
    assert values[3] == "https://github.com/howie6879/ruia"
コード例 #4
0
def test_attr_field_many_even_there_is_only_one_in_html():
    field = AttrField(css_select="div.brand a", attr="href", many=True)
    value = field.extract(html_etree=html_etree)
    assert value[0] == "https://github.com"
    assert len(value) == 1
コード例 #5
0
def test_attr_field():
    attr_field = AttrField(css_select="div.brand a", attr="href")
    value = attr_field.extract(html_etree=html_etree)
    assert value == "https://github.com"