2014-12-03 2 views
1

내 안드로이드 애플 리케이션에서 URL을 다 쓸 필요가 있습니다. URL을 반환이 아래의 HTML 코드 블록 :안드로이드에서 Html 스크랩

<div id="main"> 
    <div id="header"> 
    <form action="/search_db.php" id="f1" method="GET"> 
    <div style="float:left; width:829px;"> 
    <span style="margin:15px;"><a href="http://mp3skull.com/"><img src="http://mp3skull.com/img/logo.jpg" border="0" alt="mp3skull.com - mp3 downloads" style="vertical-align:middle;" /></a></span> 
    <input type="text" name="q" id="sfrm" autocomplete="off" value="feel good inc gorillaz" style="font-size:18px; vertical-align:middle; width:470px;"> 
    <input type="hidden" name="fckh" value="c1935e9a779034dec31fe7117c456eb8"> 
    <input type="submit" id="search_button" value="Search" style="font-size:18px; vertical-align:middle;"> 
    </div> 
    <div style="float:left; text-align:right;"> 
    </div> 
    <div style="clear:both;"></div> 
    </form><script type="text/javascript">document.getElementById('sfrm').focus();InstallAC(document.getElementById('f1'), document.getElementById('sfrm'), document.getElementById('search_button'), '', 'en');</script> 
</div> 

이 친절하게 나에게 jsoup을 사용하여 자바

답변

2

에 반환 된 HTML 코드의 값을 추출하는 방법의 예를 보여줍니다.

Document doc = Jsoup.connect("http://your/url/here").get(); // or Jsoup.parse(htmlString); 
Elements header = doc.select("#header"); //access to <div id="header">...</div> 
    Elements inputs = header.select("input"); 
    for(Element input : inputs){ 
     System.out.println(input); //print <input>....</input> 
     System.out.println(input.attr("id")); //printing attribute id 
    }