Java Android中的抓取Html
我需要在我的android应用程序中创建一个url。url将在下面返回此Html代码块:Java Android中的抓取Html,java,android,html,web-scraping,Java,Android,Html,Web Scraping,我需要在我的android应用程序中创建一个url。url将在下面返回此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
<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>
document.getElementById('sfrm').focus();InstallAC(document.getElementById('f1')、document.getElementById('sfrm')、document.getElementById('search_按钮')、'en');
请给我一个示例,说明如何使用java提取返回的html代码的值
Document doc=Jsoup.connect(“http://your/url/here“”。get();//或Jsoup.parse(htmlString);
元素标题=单据选择(“#标题”)//访问。。。
元素输入=标题。选择(“输入”);
用于(元素输入:输入){
System.out.println(输入);//打印。。。。
System.out.println(input.attr(“id”);//打印属性id
}
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
}