Webmagic crawls the title and content of all articles on the webpage.
Package com. ij34; import us. codecraft. webmagic. site; import us. codecraft. webmagic. page; import us. codecraft. webmagic. spider; import us. codecraft. webmagic. pipeline. filePipeline; import us. codecraft. webmagic. processor. pageProcessor; import java. util. list; public class HuxiuTest implements PageProcessor {@ Override public void process (Page page) {List <String> requests = page. getHtml (). links (). regex (". * article. *"). all (); page. addTargetRequests (requests); page. putField ("title", page. getHtml (). xpath ("// div [@ class = 'Wrap-left pull-left'] // h1/text ()"); page. putField ("author", page. getHtml (). xpath ("// div [@ class = 'Article-author'] // a/text ()"); page. putField ("time", page. getHtml (). xpath ("// div [@ class = 'column-link-box']/span [1] // text ()"); page. putField ("content", page. getHtml (). xpath ("// div [@ class = 'Article-content-wrapp']");} @ Override public Site getSite () {return Site. me (). setDomain ("www.huxiu.com");} public static void main (String [] args) {Spider. create (new HuxiuTest ()). addUrl ("https://www.huxiu.com /"). addPipeline (new FilePipeline ("D: \ webmagic \ data \\")). run ();}}