0
안녕 모두, 필자는이 두 기능을 구글 맞춤 검색을 수행 :추출 구글 맞춤 검색 결과
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
try {
// looking for
String strNoSpaces = str.replace(" ", "+");
// Your API key
String key="AIzaSyBewkknFVuG68bIjao5sg98kYuPmZuNLvs";
// Your Search Engine ID
String cx = "013787635589838199944:m7q-rztdo1w";
String url2 = "https://www.googleapis.com/customsearch/v1?q=" + strNoSpaces + "&key=" + key + "&cx=" + cx + "&alt=json";
Log.d("search", "Url = "+ url2);
String result2 = httpGet(url2);
result.setText(result2);
}
catch(Exception e) {
System.out.println("Error1 " + e.getMessage());
}
}
public String httpGet(String urlStr) throws IOException, JSONException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if(conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
Log.d("search", "Connection status = " + conn.getResponseMessage());
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while((line = rd.readLine()) != null) {
Log.d("search", "Line =" + rd.readLine());
sb.append(line+"\n");
}
rd.close();
conn.disconnect();
return sb.toString();
}
그리고 이것이 내가 예를 들어 검색은 텍스트 뷰에서 볼 수있는 결과이다 "노래방" :
내가 원하는 것은 텍스트 뷰에만 제목 및 각 비디오의 링크에서 볼 수있다. 이 경우에는 "King King Karaoke"와 그 다음 검색 항목이 있지만 어떻게 할 수 있는지 **** 아이디어가 있습니다 :) 대단히 감사합니다.