Google 검색에서 모든 웹 사이트 링크를 필터링하고 싶습니다. 내가 무언가를 찾고 있다면 Google이 사이트를 보여주는 모든 웹 사이트 링크를 얻고 싶습니다.검색 결과 (링크)를 Java의 Google 검색에서 제외하는 방법
먼저 전체 HTML 콘텐츠를 읽고 싶습니다. 이후에 중요한 모든 URL을 필터링하고 싶습니다. 예를 들어 -> 내가 단어 "신발 구매"를 구글에 넣으면 -> 나는 "www.amazon.in/Shoes"와 같은 링크를 얻고 싶습니다. 내 프로그램을 시작하고 경우
내가 얻을 몇 URL과 "google.de/intl/de/options/"
PS 같은 단지 구글 기반 사이트 : 나는 동일한 쿼리와 페이지 소스를 확인 (크롬 + 및 파이어 폭스 브라우저에서 "구매 + 신발") 크롬 브라우저는 파이어 폭스 브라우저보다 훨씬 더 많은 콘텐츠를 제공합니다. 내 감정은 자바가 파이어 폭스 브라우저처럼 연결되기 때문에 나는 소수의 웹 사이트 결과 만 얻는다는 것이다. Google에서 이러한 모든 링크를 얻으려면 어떻게해야합니까?
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class findEveryUrl {
public static void main(String[] args) throws IOException
{
String gInput = "https://www.google.de/#q=";
// setKeyWord asks you to enter the keyword into the console
String fullUrl = gInput + setKeyWord();
//fullUrl is used for the InputStream and "www." is the string, which is used for splitting
findAllSubs(fullUrl, "www.");
//System.out.println("given url: " + fullUrl);
}
/*
* @param <T> String type.
* @param urlString has to be the full Url.
* @param splitphrase is the String which is used for splitting.
* @return void
*/
static void findAllSubs(String urlString, String splitphrase)
{
try
{
URL url = new URL(urlString);
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine ;
String array[];
while ((inputLine = in.readLine()) != null){
inputLine += in.readLine();
array = inputLine.split(splitphrase);
arrayToConsol(array);
}
}catch (IOException e) {
e.printStackTrace();
}
}
/*
* urlQuery() asks you for the search keyword for the google query
* @return returns the keyword, which you wrote into the console
*/
public static String setKeyWord(){
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a KeyWord: ");
//googles search engine url
String keyWord = null;
try {
keyWord = console.readLine();
} catch (IOException e) {
// shouldn't be happen
e.printStackTrace();
}
return keyWord;
}
public static void arrayToConsol(String[] array){
for (String item : array) {
System.out.println(item);
}
}
public static void searchQueryToConsole(String url) throws IOException{
URL googleSearch = new URL(url);
URLConnection yc = googleSearch.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}}
Daredesm, 빠른 답장 =) –