Salut je veux créer un robot web en java dans lequel je veux retrive certaines données comme le titre, la description de la page Web et de stocker les données dans la base de donnéesComment créer un robot d'indexation Web dans Java?
0
A
Répondre
0
Jetez un oeil à cet exemple: http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/
Et pour robots d'exploration open source existantes: http://java-source.net/open-source/crawlers/java-web-crawler
2
Si vous voulez faire votre propre usage du HttpClient inclus dans le API Android.
Exemple d'utilisation de HttpClient (il vous suffit d'analyser le:
public class HttpTest {
public static void main(String... args)
throws ClientProtocolException, IOException {
crawlPage("http://www.google.com/");
}
static Set<String> checked = new HashSet<String>();
private static void crawlPage(String url) throws ClientProtocolException, IOException {
if (checked.contains(url))
return;
checked.add(url);
System.out.println("Crawling: " + url);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
HttpResponse response = client.execute(request);
Reader reader = null;
try {
reader = new InputStreamReader(response.getEntity().getContent());
Links links = new Links();
new ParserDelegator().parse(reader, links, true);
for (String link : links.list)
if (link.startsWith("http://"))
crawlPage(link);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
static class Links extends HTMLEditorKit.ParserCallback {
List<String> list = new LinkedList<String>();
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (t == HTML.Tag.A)
list.add(a.getAttribute(HTML.Attribute.HREF).toString());
}
}
}
1
Vous pouvez utiliser crawler4j Crawler4j est un crawler Java open source qui fournit une interface simple pour l'exploration du Web Vous pouvez configurer un.. .
0
web crawler multi-thread dans quelques heures Vous pouvez utiliser Webcollector: https://github.com/CrawlScript/WebCollector
Demo basé sur Webcollector 2,05:
import cn.edu.hfut.dmic.webcollector.crawler.BreadthCrawler;
import cn.edu.hfut.dmic.webcollector.model.Links;
import cn.edu.hfut.dmic.webcollector.model.Page;
import java.util.regex.Pattern;
import org.jsoup.nodes.Document;
/**
* Crawl news from yahoo news
*
* @author hu
*/
public class YahooCrawler extends BreadthCrawler {
/**
* @param crawlPath crawlPath is the path of the directory which maintains
* information of this crawler
* @param autoParse if autoParse is true,BreadthCrawler will auto extract
* links which match regex rules from pag
*/
public YahooCrawler(String crawlPath, boolean autoParse) {
super(crawlPath, autoParse);
/*start page*/
this.addSeed("http://news.yahoo.com/");
/*fetch url like http://news.yahoo.com/xxxxx*/
this.addRegex("http://news.yahoo.com/.*");
/*do not fetch url like http://news.yahoo.com/xxxx/xxx)*/
this.addRegex("-http://news.yahoo.com/.+/.*");
/*do not fetch jpg|png|gif*/
this.addRegex("-.*\\.(jpg|png|gif).*");
/*do not fetch url contains #*/
this.addRegex("-.*#.*");
}
@Override
public void visit(Page page, Links nextLinks) {
String url = page.getUrl();
/*if page is news page*/
if (Pattern.matches("http://news.yahoo.com/.+html", url)) {
/*we use jsoup to parse page*/
Document doc = page.getDoc();
/*extract title and content of news by css selector*/
String title = doc.select("h1[class=headline]").first().text();
String content = doc.select("div[class=body yom-art-content clearfix]").first().text();
System.out.println("URL:\n" + url);
System.out.println("title:\n" + title);
System.out.println("content:\n" + content);
/*If you want to add urls to crawl,add them to nextLink*/
/*WebCollector automatically filters links that have been fetched before*/
/*If autoParse is true and the link you add to nextLinks does not match the regex rules,the link will also been filtered.*/
// nextLinks.add("http://xxxxxx.com");
}
}
public static void main(String[] args) throws Exception {
YahooCrawler crawler = new YahooCrawler("crawl", true);
crawler.setThreads(50);
crawler.setTopN(100);
//crawler.setResumable(true);
/*start crawl with depth of 4*/
crawler.start(4);
}
}
Questions connexes
- 1. Comment créer un robot d'indexation Web dans ASP.NET?
- 2. construire un robot d'indexation Web
- 3. Robot Simulation en Java
- 4. Performances createScreenCapture du robot Java
- 5. Comment créer une variable Robot globale sans lancer AWTException?
- 6. Aide pour le robot d'indexation Web requise
- 7. Comment créer des contrôles Web personnalisés Java?
- 8. Comment créer une application web java
- 9. Comment puis-je commencer à créer un service Web Java?
- 10. Comment créer un web mobile et une transaction sur java
- 11. Impossible de créer un service Web Java dans Eclipse
- 12. Robot Java classe XP vs Vista Win7
- 13. Recommandations de langage pour un robot d'indexation Web efficace
- 14. Comment créer un objet persistant dans Java
- 15. Utilisation du robot d'indexation Web pour la comparaison de prix
- 16. Meilleure approche pour créer un robot d'indexation Web personnalisé pour trouver des sites avec un texte arbitraire dans l'URL?
- 17. Existe-t-il un robot Web ouvert et simplement extensible?
- 18. Autorisations de plugin dans un robot IRC
- 19. Comment créer un service Web?
- 20. Comment puis-je créer un démon Java?
- 21. Comment créer un PlugIn Java?
- 22. Comment un Robot répond-il en privé dans Google Wave?
- 23. Comment gérer l'erreur OUT OF MEMORY pour plusieurs threads dans un Web Crawler Java
- 24. Comment déterminer si un utilisateur accédant à votre site Web n'est pas un robot?
- 25. Comment un robot d'exploration assure-t-il une couverture maximale?
- 26. Comment créer un lien vers un site web dans Cocoa?
- 27. Comment puis-je créer un journal pour les services Web dans un projet Web dynamique en Java?
- 28. comment créer un compteur dans un programme dr Java
- 29. Construction d'un robot d'indexation automatique
- 30. Comment créer une servlet Java dans Eclipse?
J'aime HtmlUnit, mais je ne sais pas comment cela fonctionnerait sur Android ... – MatrixFrog
Dites-moi comment utiliser HtmlUnit pour créer un robot d'indexation sur Internet. Premièrement, je veux analyser certaines données et les stocker en db. –