We are trying to retrieve the best guess for an image given the html of the search results page returned by Google. We know that the best guess for the image has the class qb-b so we tried selecting elements with 'a' tag using the .select method. Yet when we printed the document retrieved using the get method of jsoup, the document did not contain any "best guess" string.
The code we wrote is below. How can we fix it?
String newUrl = connect1.getHeaderField("Location");
Document doc = Jsoup.connect(newUrl.toString()).get();
Elements bestguess = doc.select("a.qb-b");
System.out.println(bestguess.toString());
You have to set User-Agent header. Google will redirect you to main page instead. Try: