This Android WebScraper class allows you to extract content from a web page using Java. It includes basic error handling and uses HttpURLConnection for web interactions.
-
Initialize WebScraper:
WebScraper webScraper = new WebScraper("https://example.com");
-
Get Web Page Content:
String pageContent = webScraper.getContent();
-
Find Patterns in Content:
String[] patterns = webScraper.findWithPattern("<your-regex-pattern>");
WebScraper webScraper = new WebScraper("https://example.com");
String pageContent = webScraper.getContent();
if (!pageContent.equals("(void)")) {
Log.e("WebScraper", "Web Page Content:\n" + pageContent);
String[] patterns = webScraper.findWithPattern("<your-regex-pattern>");
Log.e("Matched Patterns:");
for (String pattern : patterns) {
Log.e(pattern);
}
} else {
Log.e("WebScraper", "Failed to fetch web page content.");
}
- Ensure you have the internet permission in your AndroidManifest.xml file.
Esta classe Android WebScraper permite extrair conteúdo de uma página da web usando Java. Inclui tratamento básico de erros e usa HttpURLConnection para interações web.
-
Inicializar o WebScraper:
WebScraper webScraper = new WebScraper("https://example.com");
-
Obter Conteúdo da Página Web:
String pageContent = webScraper.getContent();
-
Encontrar Padrões no Conteúdo:
String[] patterns = webScraper.findWithPattern("<seu-padrao-de-regex>");
WebScraper webScraper = new WebScraper("https://example.com");
String pageContent = webScraper.getContent();
if (!pageContent.equals("(void)")) {
Log.e("WebScraper", "Conteúdo da Página Web:\n" + pageContent);
String[] patterns = webScraper.findWithPattern("<seu-padrao-de-regex>");
Log.e("Padrões Encontrados:");
for (String pattern : patterns) {
Log.e(pattern);
}
} else {
Log.e("WebScraper", "Falha ao obter o conteúdo da página web.");
}
- Certifique-se de ter a permissão de internet no arquivo AndroidManifest.xml.