craweler4j를 설정하려고합니다. Netbeans의 소스에서 구축하고 있습니다. 나는 crawler4j의 3.5 버전을 사용하고 호출하는 클래스는 한 번 사이트에 기재의 경우와 동일합니다 -Crawler4j - NoSuchMethod getOutgoingUrls()
public class MyCrawler extends WebCrawler {
private final static Pattern FILTERS = Pattern.compile(".*(\\.(css|js|bmp|gif|jpe?g"
+ "|png|tiff?|mid|mp2|mp3|mp4"
+ "|wav|avi|mov|mpeg|ram|m4v|pdf"
+ "|rm|smil|wmv|swf|wma|zip|rar|gz))$");
/**
* You should implement this function to specify whether
* the given url should be crawled or not (based on your
* crawling logic).
*/
@Override
public boolean shouldVisit(WebURL url) {
String href = url.getURL().toLowerCase();
return !FILTERS.matcher(href).matches() && href.startsWith("http://www.ics.uci.edu/");
}
/**
* This function is called when a page is fetched and ready
* to be processed by your program.
*/
@Override
public void visit(Page page) {
String url = page.getWebURL().getURL();
System.out.println("URL: " + url);
if (page.getParseData() instanceof HtmlParseData) {
HtmlParseData htmlParseData = (HtmlParseData) page.getParseData();
String text = htmlParseData.getText();
String html = htmlParseData.getHtml();
List<WebURL> links = htmlParseData.getOutgoingUrls();
System.out.println("Text length: " + text.length());
System.out.println("Html length: " + html.length());
System.out.println("Number of outgoing links: " + links.size());
}
}
}
및
public class Controller {
public static void main(String[] args) throws Exception {
String crawlStorageFolder = "/data/crawl/root";
int numberOfCrawlers = 7;
CrawlConfig config = new CrawlConfig();
config.setCrawlStorageFolder(crawlStorageFolder);
/*
* Instantiate the controller for this crawl.
*/
PageFetcher pageFetcher = new PageFetcher(config);
RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);
/*
* For each crawl, you need to add some seed urls. These are the first
* URLs that are fetched and then the crawler starts following links
* which are found in these pages
*/
controller.addSeed("http://www.ics.uci.edu/~welling/");
controller.addSeed("http://www.ics.uci.edu/~lopes/");
controller.addSeed("http://www.ics.uci.edu/");
/*
* Start the crawl. This is a blocking operation, meaning that your code
* will reach the line after this only when crawling is finished.
*/
controller.start(MyCrawler.class, numberOfCrawlers);
}
}
- 아래의 편의를 위해 재현코드에서 successfuly를 컴파일하지만 런타임 예외가 발생하면 예외가 발생합니다. 제발 제안 해주세요.
Exception in thread "Crawler 1" java.lang.NoSuchMethodError: edu.uci.ics.crawler4j.parser.HtmlParseData.getOutgoingUrls()Ljava/util/Set;
at MyCrawler.visit(MyCrawler.java:42)
at edu.uci.ics.crawler4j.crawler.WebCrawler.processPage(WebCrawler.java:351)
at edu.uci.ics.crawler4j.crawler.WebCrawler.run(WebCrawler.java:220)
at java.lang.Thread.run(Thread.java:744)
나는 코드를 파고 거기에서 같은 이름을 가진 클래스를 발견했다. 그러나 여전히 오류.
나의 대답을 받아 들일 만했다면, 제발 받아 들일 수 있을까요? – Chaiavi