2012-02-21 2 views
-1
String html = Jsoup.connect("www.example.com").get().html(); 
Scanner in = new Scanner(html); 

String links ; 
while(in.hasNext()){ 
    String line = in.nextLine(); 
    if(line.contains("sometext")){ 

String links += line.substring(line.indexOf("http").line.indexOf("</a>") + "\n"); 

    } 

私は上記のコードを持っています。 JSoupを使用してWebページのHTMLを取得した後、文字列または新しい行で区切られた配列に保存します。それが私の問題です。解析されたリンクを文字列または配列に保存するjava

答えて

0

HTMLの取得と解析には、jsoupを使用してください。また、jsoupのドキュメントaddress thisもあります。

String output = ""; 
// Get the webpage and parse it. 
Document doc = Jsoup.connect(url).get(); 
// Get the anchors with href attribute. 
// Or, you can use doc.select("a") to get all the anchors. 
Elements links = doc.select("a[href]"); 
// Iterate over all the links and process them. 
for (Element link : links) { 
    output += link.attr("abs:href"); 
} 
+0

ありがとうございました。それは正常に動作している....... –

関連する問題