我有这个谷歌搜索的代码:
int num_risultati=15;
String only="+filetype%3Ahtml+OR+filetype%3Ahtm+OR+filetype%3Axhtm+OR+filetype%3Axhtml";
String google = "http://www.google.com/search?lr=lang_en&num="+num_risultati+"&q="+only;
String search = "\"Java\" \"C\"";
String charset = "UTF-8";
String userAgent = "ExampleBot 1.0 (+http://example.com/bot)";
Elements links = Jsoup.connect(google + URLEncoder.encode(search, charset)).userAgent(userAgent).get().select("li.g>h3>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");
//System.out.println(url);
if (!url.startsWith("http")) {
continue; // Ads/news/etc.
}
System.out.println("Title: " + title);
System.out.println("URL: " + url);
System.out.println();
}除了只搜索文件html,htm,xhtm,xhtml,我还会包括到维基百科的链接,也就是以"en.wikipedia.org“开头的链接。
如何将其添加到查询中?
我试过了,但不起作用:
String only="+filetype%3Ahtml+OR+filetype%3Ahtm+OR+filetype%3Axhtm+OR+filetype%3Axhtml+OR+as_lq=en.wikipedia.org"发布于 2014-10-21 23:48:30
您可以使用以下命令过滤带有特定域名的谷歌搜索,如en.wikipedia.org:
site:en.wikipedia.org
试试这个,而不是"as_lq=en.wikipedia.org“。此外,在站点筛选器之前,您可能不需要最后一个OR运算符。
https://stackoverflow.com/questions/26490472
复制相似问题