मेरे कोड के लिए, मैं Google नया खोज शीर्षक & URL प्राप्त करना चाहता हूं।Google समाचार सामग्री को पार्स करने के लिए कोई आउटपुट
यह अतीत में काम करता था। हालांकि, मुझे नहीं पता कि यह अब क्यों काम नहीं कर रहा है?
क्या Google ने अपनी सीएसएस संरचना बदल दी है या क्या?
धन्यवाद
public static void main(String[] args) throws UnsupportedEncodingException, IOException {
String google = "http://www.google.com/search?q=";
String search = "stackoverflow";
String charset = "UTF-8";
String news="&tbm=nws";
String userAgent = "ExampleBot 1.0 (+http://example.com/bot)"; // Change this to your company's name and bot homepage!
Elements links = Jsoup.connect(google + URLEncoder.encode(search , charset) + news).userAgent(userAgent).get().select(".g>.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);
}
}
काम करता है! एक और सवाल। समय की एक विशिष्ट सीमा में समाचार प्राप्त करने के लिए, उदाहरण के लिए। एक साल, तीन साल या पांच साल? धन्यवाद – evabb
समय सीमा पैरामीटर – ProgrammersBlock