求一个PHP把远程网页保存到自己的虚拟主机服务器的程序

winjie0618 2010-07-07 10:09:08
如题,求一个能将远程网页保存到自己的虚拟主机服务器并可以自动重新添加进内容的PHP源码。
要保存的网页在http://m.weather.com.cn/data/101120301.html
目标网页的内容是
###################################################################################################
{"weatherinfo":{"city":"淄博","city_en":"zibo","date_y":"2010年7月7日","date":"庚寅年五月廿六","week":"星期三","fchh":"08","cityid":"101120301","temp1":"37℃~25℃","temp2":"35℃~24℃","temp3":"32℃~22℃","temp4":"29℃~21℃","temp5":"31℃~21℃","temp6":"34℃~22℃","tempF1":"98.6℉~77℉","tempF2":"95℉~75.2℉","tempF3":"89.6℉~71.6℉","tempF4":"84.2℉~69.8℉","tempF5":"87.8℉~69.8℉","tempF6":"93.2℉~71.6℉","weather1":"晴转多云","weather2":"多云","weather3":"雷阵雨","weather4":"雷阵雨转多云","weather5":"多云转晴","weather6":"晴","img1":"0","img2":"1","img3":"1","img4":"99","img5":"4","img6":"99","img7":"4","img8":"1","img9":"1","img10":"0","img11":"0","img12":"99","img_single":"0","img_title1":"晴","img_title2":"多云","img_title3":"多云","img_title4":"多云","img_title5":"雷阵雨","img_title6":"雷阵雨","img_title7":"雷阵雨","img_title8":"多云","img_title9":"多云","img_title10":"晴","img_title11":"晴","img_title12":"晴","img_title_single":"晴","wind1":"南风小于3级","wind2":"南风小于3级","wind3":"北风小于3级","wind4":"北风小于3级","wind5":"北风小于3级","wind6":"北风转南风小于3级","fx1":"南风","fx2":"南风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"强","index48_uv":"中等","index_xc":"较适宜","index_tr":"较不宜","index_co":"很不舒适","st1":"37","st2":"25","st3":"35","st4":"24","st5":"30","st6":"20","index_cl":"适宜","index_ls":"极适宜"}}
#######################################################################################
要求可以保存为本地的html文件。如1.html 并且在里面加入 类似于 "tianqi":"天气"这样的字段。
做PHP版的免费飞信天气预报用!
...全文
123 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hubeiphp 2010-07-07
学习学习
回复
feirou521 2010-07-07
收了!
回复
张小菜1024 2010-07-07
顶@@学习!!
回复
网站www.pjob.info的采集内容就是用的这种方法。
http://topic.csdn.net/u/20100706/14/dd3bd6a1-576a-46b9-a127-dabea8bb89d8.html (#35楼)
回复
[Quote=引用 1 楼 hero0524 的回复:]

$str = file_get_contents("http://m.weather.com.cn/data/101120301.html");
[/Quote]

这个对于有的来说是不行的哦~

一个比较完整的函数gethttpcnt ,通过CURL来获取HTML文件内容:

//获取远程网址的内容,采用curl,一般用于外站的内容获取
function gethttpcnt($url,$username = '',$password = '',$timeout = 5){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

//在需要用户检测的网页里需要增加下面两行
if($username && $password){
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
}
$cnt = curl_exec($ch);
curl_close($ch);
return $cnt;
}
回复
winjie0618 2010-07-07
关键问题是我是菜鸟。所以只会等高手写出源码。还请高手不吝指教!!^_^
回复
在-云端 2010-07-07
[Quote=引用 1 楼 hero0524 的回复:]

$str = file_get_contents("http://m.weather.com.cn/data/101120301.html");
[/Quote]
写进本地文件:file_put_contents('1.html',$str);


如果要往里面+东西可以用正则!
回复
张小菜1024 2010-07-07
$str = file_get_contents("http://m.weather.com.cn/data/101120301.html");
回复
CunningBoy 2010-07-07
你现在问得太泛了~~~~
参照PHP手册中cURL的说明,自己动手做一下,才能发现问题,别人才能帮你具体解决。
回复
winjie0618 2010-07-07
[Quote=引用 4 楼 default7 的回复:]
引用 1 楼 hero0524 的回复:

$str = file_get_contents("http://m.weather.com.cn/data/101120301.html");


这个对于有的来说是不行的哦~

一个比较完整的函数gethttpcnt ,通过CURL来获取HTML文件内容:

PHP code

//获取远程网址的内容,采用curl,一般用于外站……
[/Quote]
好像不是很全的php代码吧?本人只是略懂html代码。所以还请明示。
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告