| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
WebCollector is an open source Java crawler which provides some simple interfaces for crawling the Web。You can setup a multi-threaded web crawler in 5 minutes!
###INSTALL Add dependency to your pom.xml
<dependency>
<groupId>cn.edu.hfut.dmic.webcollector</groupId>
<artifactId>WebCollector</artifactId>
<version>1.42</version>
</dependency>
###DEMO This DEMO extracts all the questions asked at http://www.zhihu.com/ . You need to create a crawler class that extends BreadthCrawler.
public class ZhihuCrawler extends BreadthCrawler{
/**
* This function is called when a page is fetched and
* ready to be processed by your program.
*/
@Override
public void visit(Page page) {
String question_regex="^http://www.zhihu.com/question/[0-9]+";
if(Pattern.matches(question_regex, page.getUrl())){
System.out.println("processing "+page.getUrl());
/*extract title of the page*/
String title=page.getDoc().title();
System.out.println(title);
/*extract the content of question*/
String question=page.getDoc().select("div[id=zh-question-detail]").text();
System.out.println(question);
}
}
/**
* start crawling
*/
public static void main(String[] args) throws IOException{
ZhihuCrawler crawler=new ZhihuCrawler();
crawler.addSeed("http://www.zhihu.com/question/21003086");
crawler.addRegex("http://www.zhihu.com/.*");
/*start the crawler with depth=5*/
crawler.start(5);
}
}
As can be seen in the above code,there are one function that should be overridden:
###The architecture of WebCollector
中文教程: https://github.com/CrawlScript/WebCollector/blob/master/README.zh-cn.md
| Back | FazBrowse Home | New Git URL |