All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.codecraft.webmagic.samples.HuxiuProcessor Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package us.codecraft.webmagic.samples;

import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.List;

/**
 * @author [email protected] 
*/ public class HuxiuProcessor implements PageProcessor { @Override public void process(Page page) { List requests = page.getHtml().links().regex(".*article.*").all(); page.addTargetRequests(requests); page.putField("title",page.getHtml().xpath("//div[@class='clearfix neirong']//h1/text()")); page.putField("content",page.getHtml().xpath("//div[@id='neirong_box']/tidyText()")); } @Override public Site getSite() { return Site.me().setDomain("www.huxiu.com"); } public static void main(String[] args) { Spider.create(new HuxiuProcessor()).addUrl("http://www.huxiu.com/").run(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy