正则表达式获取html标签
okhttp返回了一个html页面,已经转成string,有一段是<tr><tdclass='ppprod_lefttdppprod_cell'>上次余额:</td><t...
okhttp返回了一个html页面,已经转成string,有一段是<tr><td class='ppprod_lefttd ppprod_cell'>上次余额:</td><td class='ppprod_confirm ppprod_cell' id=''><span name="item22" id="item22" delim="" class="" >114.74</span> </td></tr>
现在要获取114.74需要怎么做呢 展开
现在要获取114.74需要怎么做呢 展开
展开全部
方法1:
var d = document.createElement("div");
d.innerHTML = '<tr><td class="ppprod_lefttd ppprod_cell">上次余额:</td><td class="ppprod_confirm ppprod_cell" id=""><span name="item22" id="item22" delim="" class="" >114.74</span> </td></tr>';
alert(d.getElementsByTagName("span")[0].innerText);
用正则
var str = '<tr><td class="ppprod_lefttd ppprod_cell">上次余额:</td><td class="ppprod_confirm ppprod_cell" id=""><span name="item22" id="item22" delim="" class="" >114.74</span> </td></tr>';
alert(str.match(/^.*>(\d+(\.?\d+)?)<.*$/)[1]);
var d = document.createElement("div");
d.innerHTML = '<tr><td class="ppprod_lefttd ppprod_cell">上次余额:</td><td class="ppprod_confirm ppprod_cell" id=""><span name="item22" id="item22" delim="" class="" >114.74</span> </td></tr>';
alert(d.getElementsByTagName("span")[0].innerText);
用正则
var str = '<tr><td class="ppprod_lefttd ppprod_cell">上次余额:</td><td class="ppprod_confirm ppprod_cell" id=""><span name="item22" id="item22" delim="" class="" >114.74</span> </td></tr>';
alert(str.match(/^.*>(\d+(\.?\d+)?)<.*$/)[1]);
追问
我是java提取
追答
java也有正则的嘛
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询