<分区>
我想从站点的源代码中获取一些数据并编辑该源代码,然后将其添加到数据库中。我知道 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 - 什么 css 位置 : or overflow do you use for smaller screens/minimized screens?
css - 如何使此 Google 字体在 Internet Explorer 11 上工作
php - OAuthTokenCredential 的 Paypal SDK 问题
php - 在 netbeans 中没有扩展的语法高亮显示 PHP shell 脚本
php - Symfony Form Collection - 如何获取实体 id?
html - 显示属性 - 具有行内宽度的 block 行为