Search in sources :

Example 1 with Selectable

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());
}
Also used : Selectable(us.codecraft.webmagic.selector.Selectable)

Example 2 with Selectable

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");
}
Also used : Selectable(us.codecraft.webmagic.selector.Selectable) Html(us.codecraft.webmagic.selector.Html) Test(org.junit.Test)

Aggregations

Selectable (us.codecraft.webmagic.selector.Selectable)2 Test (org.junit.Test)1 Html (us.codecraft.webmagic.selector.Html)1