![](/img/trans.png)
[英]How to retrieve a specific table from webpage using Jsoup [ Android ]
[英]How to read the specific content from the webpage using the jsoup and jericho api for dynamic page
我現在使用jsoup api從網頁中讀取內容,但是它正在讀取所有內容,但是我不希望所有內容我想要動態給定URL的特定內容,我也嘗試了Jericho api,但它沒有解決我的問題。
讓我們舉這個例子
Document doc = Jsoup.connect("http://www.url.com").get();
Elements elem = doc.select("span.content");
System.out.println(elem.get(1).text());
System.out.println(elem.get(2).text());
如果網址包含此數據
<html>
<body>
<span class="content">data one</span>
<span class="content">data two</span>
<a class="content">data three</a>
</body>
</html>
現在,您將僅獲得這些第一和第二個元素
<span class="content">data one</span>
<span class="content">data two</span>
更新
//this is the help i can do to you bro
$search="data two";
$re = "/(.*)($search)(.*)/i";
//for example the doc object is having this html elements
$str = '<span class="content">data one</span>
<span class="content">data two</span>
<span class="content">data two</span>
<a class="content">data three</a>';
preg_match_all($re, $str, $matches);
print_r($matches[0]);
輸出值
Array
(
[0] => <span class="content">data two</span>
[1] => <span class="content">data two</span>
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.