我有困難從谷歌檢索50個結果。檢索從谷歌使用java的50個結果
我使用這個:
public static List Retrieve(String entry){
List entryList = new ArrayList();
try {
// string new entry is making the keywords into query that can be known by google
String newEntry = (java.net.URLEncoder.encode(entry, "UTF-8").replace("+", "%20"));
// inputing the keywords to google search engine
URL url = new URL("http://www.google.co.id/search?q=" + newEntry + "&hl=en&num=10&lr=&ft=i&cr=&safe=images&tbs=");
// makking connection to the internet
URLConnection urlConn = url.openConnection();
urlConn.setUseCaches(false);
urlConn.setRequestProperty("User-Agent", "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");
// getting the input stream of page html into bufferedreader
BufferedReader buffReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String line;
StringBuffer buffer = new StringBuffer();
// getting the input stream of html into stringbuffer
while ((line = buffReader.readLine()) != null) {
buffer.append(line);
}
// finding the links
Pattern p = Pattern.compile(GOOGLE);
Matcher m = p.matcher(buffer.toString().toLowerCase());
while (m.find()) {
String link = m.group(0);
// putting the links of google search into list
entryList.add(link);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return entryList;
}
但它只能說明只有十結果。
你如何檢索你的數據? –
嗯,我可以通過輸入一個搜索詞並瀏覽它們來獲得數百萬個結果...嚴重的是,您如何嘗試檢索這些結果?你能顯示任何代碼嗎? – Thomas
我想檢索它們作爲列表,結果列表爲50個結果 – Carlo