doufan3958 2016-02-05 05:40
浏览 135

如何解析HTML DOM并选择包含特定字符串的元素?

There is a HTML structure like this:

<div>
    <b>
        <label>Company-Name : Anything</label>
    </b>
</div>
<div>
    <b>
        <label>First-Name : Alex</label>
    </b>
</div>
<div>
    <b>
        <label>Cell-phone : 035123913</label>
    </b>
</div>

I have this string: First-Name : and I need to get Alex. In other word, how can I search for string and then select all of that element?

Note1: Always this string First-Name is unique in the page.

Note2: Those elements don't have a constant order. I mean sometimes there is some new <div><b><label> after or before that structure. So the best option is searching for that string.

Note3: I'm using this library.

  • 写回答

1条回答 默认 最新

  • donglu9898 2016-02-05 05:46
    关注

    Correct spelling to "label" first. You can use jquery's $.each to loop through the labels. In the loop, use PHP's strpos to see if the value contains "First-name :". If it does, then you can do an explode() on it and index 1 will be the name you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题