Voy a raspar todos los resultados en todas las páginas con la búsqueda de Google. Restringí el rango de tiempo de búsqueda para que fuera: 1/1/2016 al 31/12/2016
String string = google + URLEncoder.encode(search , charset) + news+"&tbs=cdr%3A1%2Ccd_min%3A1%2F1%2F2016%2Ccd_max%3A12%2F31%2F2016";Veo que esto no está funcionando.
Estoy usando JSoup.
Ahora raspo con éxito todos los resultados en un número específico de páginas. numberOfResultpages
Pero quiero raspar todos los resultados en cada página que Google pueda encontrar (NO en un número específico de páginas)
Aquí está mi trabajo.
public static void main(String[] args) throws UnsupportedEncodingException, IOException { String[] line = new String[100]; final int[] score = { 0}; String google = "http://www.google.com/search?q="; String search = "stackoverflow"; String charset = "UTF-8"; String news="&tbm=nws"; String string = google + URLEncoder.encode(search , charset) + news+"&tbs=cdr%3A1%2Ccd_min%3A1%2F1%2F2016%2Ccd_max%3A12%2F31%2F2016"; int numberOfResultpages = 10; // >==grabs specific number of pages only int idx = 0; for (int i = 0; i < numberOfResultpages; i++) { Document document = Jsoup.connect(string).userAgent(userAgent) .data("start",""+i).get(); Elements links = document.select( ".r>a"); for (Element link : links) { String title = link.text(); String url = link.absUrl("href"); // Google returns URLs in format "http://www.google.com/url?q=<url>&sa=U&ei=<someKey>". url = URLDecoder.decode(url.substring(url.indexOf('=') + 1, url.indexOf('&')), "UTF-8"); if (!url.startsWith("http")) { continue; // Ads/news/etc. } System.out.println("Title: " + title); System.out.println("URL: " + url); line[idx++]=title; // } } }