PHP 简单的小偷程序

小偷程序:把远程网站上的数据(图片,网页及其他文件)抓取到本地,处理后再显示

正则表达式: 用于字符串的模式分割 、匹配、查找及替换操作。
相关函数:
int ereg ( string $pattern , string $string [, array &$regs ] )
若省略参数返回的数组,找到则返回值为 True 否则 返回 False
与之对应  eregi() 不区分大小写。  
  string  file_get_contents  (   string $filename  [,   bool $use_include_path = false  [,   resource $context[,   int $offset = 0  [,   int $maxlen  ]]]] )
读取整个文件,比如:

用此函数可以获取网页信息
他就是小偷程序的基础。
比如:
<?php
$url=file_get_contents(" http://www.ubuntu.org.cn/index_kylin");
echo $url;
?>


但是对于另一个网站:
<?php
$url=file_get_contents(" http://www.alangzhong.com/index.html");
echo $url;
?>
发现很多的背景图片是看不见的。



查看网页源代码我们发现,这是
<img width="116" height="98" 
src="/upload/201503/b123ec26-bb8f-43be-b5ad-cdf45153d053.png"/>
图片的地址使用了相对路径,而我们本地没有这样的文件,当然显示不出来。

用正则表达式选定图片,然后远程地址替换相对路径:
下面代码的超时问题没有解决。

<?php
//ini_set('max_execution_time', '0');   //三者都没用啊,一直超时
//@ini_set('default_socket_timeout', 20000);
//set_time_limit(2); 
$url=file_get_contents("http://www.alangzhong.com/index.html");
//echo $url;
$fp = @fopen($url, "r") or die("超时");  //为什么不断超时
$contents = file_get_contents($url);
eregi("<img width=\"116\" height=\"98\" src=\"/upload/201503/b123ec26-bb8f-43be-b5ad-cdf45153d053.png\"/>",$contents,$rg);
//  远程地址替换相对路径
$rg[1]=str_replace("src=\"../upload/","src=\"http://www.alangzhong.com/index.html/upload/",$rg[1]);

echo $rg[1];
?>






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值