【发布时间】:2014-01-15 00:31:42
【问题描述】:
我正在使用 PHP 代码使用 PHP Simple HTML DOM Parser 解析网站,然后在 htm 中保存多个 div 文件。我遇到的问题是保存 DOM 树。到目前为止,它正在使用 FILE_PUT_CONTENTS 保存,并且必须使用 FILE_APPEND 以便 div 的 不会相互覆盖。但这是一个问题,因为每次运行 PHP 代码时,它都会向我不想要的文件添加更多内容。我看了几个选项,但无法理解。我希望你能帮助我并感谢你的时间。
下面是我目前的PHP代码
include( 'site/simple_html_dom.php');
$html = file_get_html('http://roosterteeth.com/home.php');
foreach ($html->find('div.streamIndividual') as $div)
{
file_put_contents('site/test.htm', $div, FILE_APPEND | LOCK_EX);
}
以下是我的 HTML 代码,其中包含经过编辑的 PHP
<?php
include( 'site/simple_html_dom.php');
$html = file_get_html('http://roosterteeth.com/home.php');
$divContents = array();
foreach ($html->find('div.streamIndividual') as $div)
{
$divContents[] = $div->outertext;
}
file_put_contents('site/test.htm', implode(PHP_EOL, $divContents));
?>
<script type="text/javascript" src="site/jquery.js"></script>
<script type="text/javascript">
$('document').ready(function() {
$('#wrap').load('site/test.htm');
});
</script>
</head>
<body>
<div id="wrap">
</div>
</body>
以下是 test.htm
的链接【问题讨论】:
标签: javascript php jquery html dom