質問
を使わずに外部の図書館は何が最も簡単な方法を取得すのウェブサイトのHTMLコンテンツを文字列?
解決
私は現在使用します:
String content = null;
URLConnection connection = null;
try {
connection = new URL("http://www.google.com").openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter("\\Z");
content = scanner.next();
scanner.close();
}catch ( Exception ex ) {
ex.printStackTrace();
}
System.out.println(content);
ない場合があります。
他のヒント
これるようになったと言っても私には:
URL url = new URL(theURL);
InputStream is = url.openStream();
int ptr = 0;
StringBuffer buffer = new StringBuffer();
while ((ptr = is.read()) != -1) {
buffer.append((char)ptr);
}
だけれど、その他のソリューション(s)より効率的です。
W このポストに他のスレッド, ものの、そのままれ。とは思わないは思いきやすください。Apacheのパッケージにアクセスできるのだけを使用 import org.apache.commons.HttpClient
上部のコードです。
編集:忘れのリンク;)
アフコテリクとアフタハイバニラ-Javaんおよ。利用Groovy;-)
String siteContent = new URL("http://www.google.com").text
そのいない図書館のものというツールカールは設置のサーバーまたは簡単にインストールubuntuによる
sudo apt install curl
その後の取得htmlページや店舗からファイルのような例
curl https://www.facebook.com/ > fb.html
このホームページのhtml.できるブラウザです。
所属していません StackOverflow