Ⅰ 用jsoup解析網頁,取到class標簽內容後
總結一下Jsoup提供的方法:
獲取元素的有:
getElementById(String id)
getElementsByTag(String tag)
getElementsByClass(String className)
getElementsByAttribute(String key)
siblingElements(), firstElementSibling(), lastElementSibling(); nextElementSibling(), previousElementSibling()
parent(), children(), child(int index)
獲取元素數據:
attr(String key) 獲取屬性
attr(String key, String value) 設置屬性
attributes() 獲取所有屬性
id(), className() and classNames()
text() 獲取文字內容
text(String value) 設置文字內容
html() 獲取html內容
html(String value) 設置html內容
outerHtml()
data() 獲取類似script,style的數據內容
tag() and tagName()
操作HTML內容:
append(String html), prepend(String html)
appendText(String text), prependText(String text)
appendElement(String tagName), prependElement(String tagName)
html(String value)
Ⅱ jsoup如何獲取<A TARGET=_blank>中的數據
可以使用正則表達式匹配的
Ⅲ 利用Jsoup獲取具體標簽屬性值
doc.select("meta[name=description]"),來get(0).attr("content")
大致是這么自寫的,你可以研究一下JSOUP的選擇器,
chenying99/archive/2013/01/04/2844615,html" target="_blank">http://www.cnblogs.com/chenying99/archive/2013/01/04/2844615.html
Ⅳ 使用jsoup抓取分頁的問題
覺得吧~如來果你想抓取網頁分自頁信息可以使用第三方工具進行抓取,但是問題就來了,加入你是要自己程序實現的話,這樣就很麻煩。所以建議自己實現比較好。因為分頁內容,每一頁都有一個特定的鏈接,而且很相似,就只有那個指定頁數的參數不同而已。所以你可以先用遍歷方式將每個網頁抓取後解析,然後再存起來,這樣比較實際點。
但是我建議你可以在客戶端也使用分頁模式,這樣的話,根據需求去獲取,就不會一下子請求的數據量太大。
Ⅳ jsoup在怎麼獲取特定的子節點
使用Jsoup解析html中的指定數據,十分方便。Jsoup工具十分強大,十分好用。但網上似乎沒有很好的例子,本文的目的即在於此。建議仔細閱讀代碼中的幾個例子,Jsoup解析數據不外乎這幾種類型。
第一步:將Jsoup JAR包導入項目
第二步:使用Jsoup API
1, 定位
通過div的屬性值,定位到html的div(塊),即所需要內容對應的塊。
示例代碼如下:
<div class="content">
2, 篩選數據
a, 通過標簽頭,在div中繼續篩選數據。可能會找到很多的數據,這里會用到循環。見eg1。
//eg1:解析網路音樂 Document doc = Jsoup.connect("http://list.mp3..com/top/singer/A.html").get(); Element singerListDiv = doc.getElementsByAttributeValue("class", "content").first(); Elements links = singerListDiv.getElementsByTag("a"); for (Element link: links) {