【问题标题】:how to grab content but nothing class and id using simple html dom如何使用简单的 html dom 抓取内容但没有类和 id
【发布时间】:2014-11-19 16:48:55
【问题描述】:

我对简单的 html dom 有疑问 问题是如何抓取内容但没有类和 id [使用简单的 html dom]

例如:

<div style="line-height:15px; float:left; width:100%; margin:2px 0px;">I want grab this text..
<div style="float:left; width:100%; margin-top:5px; font-weight:bold; text-align:left;">text grab2</div>
谢谢

【问题讨论】:

  • 至少试试 something
  • @Ghost 编辑并查看真实来源(我无法正确显示)
  • 我只是假设,您想获取那些不具有idclass 属性的div 中的文本?
  • 是的,我的意思是这样,但感谢 Ghost 的回答。我想获取那些没有 id 和 class 属性的 div 中的文本?

标签: php html dom curl simple-html-dom


【解决方案1】:

根据您的示例:

var divs = document.getElementsByTagName('div');

alert(divs[0].innerText);

由于您的第一个 &lt;div&gt; 没有结束标记,因此输出将是

'I want grab this text.. text grab2'

如果要获取&lt;div&gt;的第一个文本,只需关闭标签即可。

见小提琴here

【讨论】:

    猜你喜欢
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    相关资源
    最近更新 更多