Restricting URLs to seed URL domain only crawler4j

倖福魔咒の 提交于 2020-01-03 02:55:52

问题


I want crawler4j to visit pages in such a manner that they belong to domain in seed only. There multiple domains in seed. How can I do it?

Suppose I am adding seed URLs:

  • www.google.com
  • www.yahoo.com
  • www.wikipedia.com

Now I am starting the crawling but I want my crawler to visit pages (just like shouldVisit()) only in above three domains. Obviously there external links, but I want my crawler to restrict to these domains only. Sub-domain, sub-folders are okay, but not outside these domains.


回答1:


If you are trying to restrict the crawler to only urls with the same domains as the seed urls, then:

  1. Extract the domain names from the seed URLs.

  2. Write your crawler class (that extends WebCrawler) with a shouldVisit method to filter out any URLs whose domains are not in the set.

  3. Configure the controller, add the seeds and start it in the normal way ... as per the example here.




回答2:


Posted on behalf of the OP:

Got the solution here : http://code.google.com/p/crawler4j/issues/detail?id=94#c1



来源:https://stackoverflow.com/questions/19875318/restricting-urls-to-seed-url-domain-only-crawler4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!