【初心者】Java質問・相談スレッド114【歓迎】at TECH
【初心者】Java質問・相談スレッド114【歓迎】 - 暇つぶし2ch238:デフォルトの名無しさん
08/04/12 23:00:01
>>212

import java.io.*;
import java.net.*;
public class CalcClient {
  public static void main(String[] args) throws IOException {
    System.out.println(calc("3+2*(5 + 2)"));
  }
  public static String calc(String target) throws IOException {
    URL url = new URL("URLリンク(www.google.com)" + URLEncoder.encode(target, "utf-8"));
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setRequestProperty("User-Agent", "Mozilla/5.0");
    conn.connect();
    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
    String response = "";
    for (String line; (line = br.readLine()) != null; ) response += line;
    br.close();
    conn.disconnect();
    return response.replaceAll("^.*?(<h2 class=r>.*?<b>.*=\\s*(\\S+?)\\s*</b></h2>).*?$", "$2");
  }
}



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch