Home  >  Article  >  Backend Development  >  请问在这段代码的基础上 CURL 如何批量保存网页呢

请问在这段代码的基础上 CURL 如何批量保存网页呢

WBOY
WBOYOriginal
2016-06-23 13:14:281082browse

大家早上好,感谢上次fdipzone帮我解决input text提交网页保存源码的问题

如果我想用一个textarea输入很多URL,以回车作为间隔,保存每个网页,名称以数字序列为名。

下面这个代码改怎么改一下呢 谢谢

@jam00   @xmt1139057136   @fdipzone 

<html><body><div align="center"><form name="form1" method="post"><input id="url" name="url" type=text></form></div></body></html>  <?php  $url = isset($_POST['url'])? $_POST['url'] : ''; $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_TIMEOUT,5); $html = curl_exec($ch); if($html !== false){     /*echo $html;*/     $fname="vb.htm";     $fd=fopen($fname,"w");     $ok=fwrite($fd,$html);     fclose($fd); }?>


回复讨论(解决方案)

curl_setopt($ch, CURLOPT_FILE, 'vb.htm');
就自动保存到文件了,无需 17 行以后的操作

输入了多个地址,当然是切割成数组,一个个来啦

可以借鉴csdn论坛的编辑输入框

curl_setopt($ch, CURLOPT_FILE, 'vb.htm');
就自动保存到文件了,无需 17 行以后的操作

输入了多个地址,当然是切割成数组,一个个来啦


我想更简单的办法是弄很多IFRAME,然后把所有IFRAME里面的源码一起保存到本地可以吗

用WEBBROWSER 和 PHP CURL 配合就可以搞定了。

用WEBBROWSER 和 PHP CURL 配合就可以搞定了。

是的,批量处理就OK 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn