LOADING STUFF...

thinkphp 抓取网站的内容并且保存到本地的实例详解

技术教程13小时前更新 北陌
18 0 0

thinkphp 抓取网站的内容并且保存到本地的实例详解

thinkphp 抓取网站的内容并且保存到本地的实例详解

我需要写这么一个例子,到电子课本网下载一本电子书。

电子课本网的电子书,是把书的每一页当成一个图片,然后一本书就是有很多张图片,我需要批量的进行下载图片操作。

下面是代码部分:

public function download() {
$http = new OrgNetHttp();
$url_pref = “http://www.dzkbw.com/books/rjb/dili/xc7s/”;
$localUrl = “Public/bookcover/”;
$reg=”|showImg((. ));|”;
$i=1;

do {
$filename = substr(“000″.$i,-3).”.htm”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_pref.$filename);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$html = curl_exec($ch);
curl_close($ch);

$result = preg_match_all($reg,$html,$out, PREG_PATTERN_ORDER);
if($result==1) {
$picUrl = $out[1][0];
$picFilename = substr(“000″.$i,-3).”.jpg”;
$http-

© 版权声明

相关文章

暂无评论

暂无评论...