我正在尝试使用“ PHP简单HTML DOM解析器”来解析网站并将特定的“ div”另存为“ HTM”文件。我已经尝试了一些方法,但是无法保存div。
以下是我尝试过的“ PHP”代码,但由于错误而出现错误$div->save('site/test.htm');
。
include( 'site/simple_html_dom.php');
$html = file_get_html('http://roosterteeth.com/home.php');
foreach ($html->find('div.streamIndividual') as $div) {
$div->save('site/test.htm');
};
希望您能帮助我,并感谢您的宝贵时间。
你尝试过这样的事情吗?
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_put_contents('site/test.htm', $div, FILE_APPEND | LOCK_EX);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句