use of us.codecraft.webmagic.selector.Selectable in project webmagic by code4craft.
the class MamacnPageProcessor method process.
@Override
public void process(Page page) {
List<Selectable> nodes = page.getHtml().xpath("//ul[@id=ma-thumb-list]/li").nodes();
StringBuilder accum = new StringBuilder();
for (Selectable node : nodes) {
accum.append("img:").append(node.xpath("//a/@href").get()).append("\n");
accum.append("title:").append(node.xpath("//img/@alt").get()).append("\n");
}
page.putField("", accum.toString());
if (accum.length() == 0) {
page.setSkip(true);
}
page.addTargetRequests(page.getHtml().links().regex("http://www\\.mama\\.cn/photo/.*\\.html").all());
}
use of us.codecraft.webmagic.selector.Selectable in project webmagic by code4craft.
the class HtmlTest method testNthNodesGet.
@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("/a/@href").get()).isEqualTo("/xx/xx");
}
Aggregations