更换使用Jsoup文本中的标签 [英] Replacing text inside tags using Jsoup
本文介绍了更换使用Jsoup文本中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<表格的宽度=100%的边界=0的cellpadding =0CELLSPACING =1级=table_borderID =center_table>
< TBODY>
&其中; TR>
< TD宽度=25%级=heading_table_top> S。编号:LT; / TD>
< TD宽度=45%级=heading_table_top>
订单管理(教练不行,泊位号,配额)
< / TD>
&所述; TD宽度=30%类=heading_table_top>
*当前状态(没有教练,泊位号)
< / TD>
< / TR>
< / TBODY>
< /表>
我放弃一个网页,并存储在一个字符串的响应。
我然后解析成jsoup DOC
文档DOC = Jsoup.parse(结果);
然后,我用选择表
元素表= doc.select(表[ID = center_table])第一()。
现在我需要更换标签订单管理(教练不行,泊位号,配额),以订单管理使用jsoup文..任何人可以帮忙吗?
我试过
table.children()文本()的replaceAll(正则表达式来选择文本?????,订单管理)。;
解决方案
元素tablecells = doc.select(表TBODY TR TD);
会给你3个细胞。 使用一个循环来获取每个元素以
元素E = Elements.get(INT指数);
使用了 e.text()
来获取字符串。
比较或替换 String.equals(串),String.contains(),与string.replace()
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="table_border" id="center_table">
<tbody>
<tr>
<td width="25%" class="heading_table_top">S. No.</td>
<td width="45%" class="heading_table_top">
Booking Status (Coach No , Berth No., Quota)
</td>
<td width="30%" class="heading_table_top">
* Current Status (Coach No , Berth No.)
</td>
</tr>
</tbody>
</table>
I scrap a webpage and store the response in a string.
I then parse it into jsoup doc
Document doc = Jsoup.parse(result);
Then i select the table using
Element table=doc.select("table[id=center_table]").first();
Now i need to replace the text in tag "Booking Status (Coach No , Berth No., Quota)" to "Booking Status" using jsoup.. Could anybody help ?
I tried
table.children().text().replaceAll(RegEx to select the text?????, "Booking Status");
解决方案
Elements tablecells=doc.select("table tbody tr td");
will give you 3 cells. use a loop to get the each element with
Element e=Elements.get(int index);
Use the e.text()
to get the String.
Compare or replace strings with String.equals() , String.contains(), String.replace()
这篇关于更换使用Jsoup文本中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文