Commit 67eb632f authored by yihua.huang's avatar yihua.huang

test for issue #200

parent b30ca6ce
......@@ -2,6 +2,7 @@ package us.codecraft.webmagic;
import org.junit.Test;
import us.codecraft.webmagic.selector.Html;
import us.codecraft.webmagic.selector.Selectable;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -31,4 +32,18 @@ public class HtmlTest {
Html html = new Html("aaaaaaa&b");
assertThat(html.regex("(aaaaaaa&b)").toString()).isEqualTo("aaaaaaa&b");
}
@Test
public void testAHrefExtract(){
Html html = new Html("<a data-tip=\"p$t$xxx\" href=\"/xx/xx\">xx</a>");
assertThat(html.links().all()).contains("/xx/xx");
}
@Test
public void testNthNodesGet(){
Html html = new Html("<a data-tip=\"p$t$xxx\" href=\"/xx/xx\">xx</a>");
assertThat(html.xpath("//a[1]/@href").get()).isEqualTo("/xx/xx");
Selectable selectable = html.xpath("//a[1]").nodes().get(0);
assertThat(selectable.xpath("@href").get()).isEqualTo("/xx/xx");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment