2011-11-26 3 views
-2

Google에서 검색 한 결과가 50 개가 아닙니다.Google을 통해 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; 
} 

을하지만 그것은 단지 단지 10의 결과를 보여줍니다

나는 이것을 사용하고 있습니다.

+0

데이터를 어떻게 검색합니까? –

+0

음, 검색 용어를 입력하고 검색을 통해 수백만 가지 결과를 얻을 수 있습니다 ... 진지하게, 어떻게 그 결과를 검색하려고합니까? 코드를 보여줄 수 있습니까? – Thomas

+0

Google의 ToS (http://www.google.com/accounts/TOS) (즉, 항목 5.3)를 위반하는 50 개 결과 – Carlo

답변

2

루프 5 회를 통해에게 제공합니다 생각에 (10)를 추가 할 때마다이 '시작'URL에 변수를 해보

for(i=0;i<5;i++) 
{ 
    ... 
    URL url = new URL("http://www.google.co.id/search?q=" + newEntry + "&hl=en&num=10&lr=&ft=i&cr=&safe=images&tbs=&start="+(i*10)); 
    ... 
} 
+0

덕분에 많은 도움이됩니다. – Carlo

+0

답변으로 표시하거나 +1 하시겠습니까? :) – Taz

0

그럼 구글 검색 결과에 다음 페이지로 이동 나는 각 페이지는 10 개 개의 결과

+0

다음 페이지로 이동하는 방법 – Carlo

+0

페이지의 url 매개 변수를 변경하면 – Zimm3r

0

URL의 num GET 매개 변수를 10에서 50으로 변경하기 만하면됩니다.이 매개 변수는 표시 할 결과의 수를 나타냅니다.

관련 문제