php - 在php中从网站的源代码中获取数据

标签 php html css

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 7 年前

我想从站点的源代码中获取一些数据并编辑该源代码,然后将其添加到数据库中。我知道 php 的 file_get_contents 函数,但我不知道如何使用此方法获取我的数据。

原始出处:

<div id="wwww" class="ssss">
<div id="1" class="2"><p>my data : </p><div id="a" class="b">i want this data</div>
<div class="action">delete</div></div>
</div>

获取 ID 为 1 的 div 源并删除类为 action 的 div 源,最后像这样打印数据:

<div id="1" class="2"><p>my data :</p><div id="a" class="b">i want this data</div></div>

请介绍一下可以使用该方法的php函数。

最佳答案

看看PHP Simple HTML DOM Parser .它非常易于使用:

$html = file_get_html('http://www.google.com/');
$myDiv = $html->find('div[id=1]');

关于php - 在php中从网站的源代码中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32165587/

上一篇:html - 图片向左浮动,文字向右浮动(不在图片底部)

下一篇:php - 如何在文本区打印带有样式的文本? (文字出版社)

相关文章:

html - 什么 css 位置 : or overflow do you use for smaller screens/minimized screens?

css - 如何使此 Google 字体在 Internet Explorer 11 上工作

PHP连接两个表的帮助

php - OAuthTokenCredential 的 Paypal SDK 问题

php - 在 netbeans 中没有扩展的语法高亮显示 PHP shell 脚本

php - Symfony Form Collection - 如何获取实体 id?

html - 显示属性 - 具有行内宽度的 block 行为

html - CSS: border-radius//插入背景;白 Angular

html - 无法在 li 元素上应用显示属性

html - 有没有办法在不弹出信息栏的情况下使元素透明?