使用 Java 搜索 Google 本地化网络搜索
我正在尝试使用 Java 应用程序在不同国家/地区搜索 Google,即 google.co.uk、google.de 等。我发现与 Java 一起使用的 Google Ajax API 只能让您使用以下内容进行网络搜索,
URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
+ "q=information%20retrieval&key=INSERT-YOUR-KEY&userip=USERS-IP-ADDRESS");
URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer", /* Enter the URL of your site here */);
但是,这只是给我 google.com 的结果。我需要每个国家/地区的单独结果。无论如何,有没有办法用 Java 来做到这一点。
谷歌有本地搜索,但它是基于谷歌地图的,它使用经度和纬度,并提供商业搜索结果。我需要针对每个国家/地区的网页。
任何想法..
我试图用以下内容抓取 google.co.uk 的搜索结果:
但返回结果是空页。有人知道解决方法吗?
谢谢萨姆
I am trying to use a Java App to search Google in different countries, i.e. google.co.uk, google.de, etc. I found that the Google Ajax API used with Java will only let you do web search with the following
URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
+ "q=information%20retrieval&key=INSERT-YOUR-KEY&userip=USERS-IP-ADDRESS");
URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer", /* Enter the URL of your site here */);
however, that just gives me google.com's results. I need separate results for each country. Is there anyway to do this with Java.
Google has local search, but that's based on Google Maps, and it uses longitude and latitude, and provides business search results. I need web pages specific to each country.
Any ideas..
I was trying to scrape google.co.uk's search result with the following:
but the returned result is an empty page. Any one know a workaround?
thanks
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据类参考,您可以设置“hl”参数在 URL 查询中。因此,对于 UK 结果,您将指定 hl=en-gb,并且您的代码将如下所示:
我在这里假设语言影响结果,仅仅是因为这两个请求 (en v fr) 似乎会导致不同的结果:
您可以在此处找到语言代码列表:http ://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx
According to the class reference you can set a 'hl' parameter in the URL query. So for UK results you would specify hl=en-gb, and your code would look like this:
I am assuming here that the langauge affects the results, simply because these two requests (en v fr) appear to result in different results:
You can find a lst of language codes here: http://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx