21,881
社区成员
发帖
与我相关
我的任务
分享
<?php
$host = "www.123cha.com";
$referer = "http://".$host;
$fp = fsockopen ($host, 80, $errno, $errstr, 30);
if (!$fp){
echo "$errstr ($errno)<br>;n";
}else{
$request = "
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */"."*
Referer: http://$host
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: $host
Connection: Close"
."rnrn";
fputs ($fp, "$request");
while (!feof($fp))
{
$res[] = fgets($fp,1024);
}
$html = join("",$res);
fclose ($fp);
$fp = file_put_contents("123cha.html",$html);
echo "done";
}
function returnUrl($host)//$host 这里传进来的是这个网址http://zh.wikipedia.org/zh-cn/Special:随机页面
{
$referer = "http://".$host; //定义变量,并连接上一个串
$fp = fsockopen ($host, 8080, $errno, $errstr, 30); // sock 到指定地址(即上面那个)。
if (!$fp){
echo "$errstr ($errno)<br>;n"; //返回空,输出信息
}else{
$request = "
GET / HTTP/1.1
Referer: http://$host
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: $host
Connection: Close"
."rnrn";
//构造一个get
fputs ($fp, "$request");//向server 发送get请求。
while (!feof($fp))
{
$res[] = fgets($fp,1024); //记录返回的信息。
}
$html = join("",$res);//将返回数组连成一个串。
fclose ($fp); //关闭 socket
$fp = file_put_contents("url.html",$html); //保存串。
return $fp;
}
}
<?php
$host = "www.123cha.com";
$referer = "http://".$host;
//打开www.123cha.com的socket连接
$fp = fsockopen ($host, 80, $errno, $errstr, 30);
if (!$fp){
//如果打开失败,输出错误信息
echo "$errstr ($errno)<br>;n";
}else{
$request = "
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */"."*
Referer: http://$host
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: $host
Connection: Close"
."rnrn";
// 发送上面的request内容给www.123cha.com
fputs ($fp, "$request");
while (!feof($fp)){
//循环获取网站的返回内容,就是response
$res[] = fgets($fp,1024);
}
//将返回的内容拼接成HTML文档。
$html = join("",$res);
//关闭socket连接
fclose ($fp);
//将网站返回的内容写入文件123cha.html
$fp = file_put_contents("123cha.html",$html);
echo "done";
}
?>
$host = "www.123cha.com"; //网址
$referer = "http://".$host; //浏览器返回(跳转)地址
$fp = fsockopen ($host, 80, $errno, $errstr, 30);//打开一个套接字,网络数据传输
if (!$fp){//如果没有打开
echo "$errstr ($errno)<br>;n";
}else{//如果打开成功
$request = "
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */"."*
Referer: http://$host
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: $host
Connection: Close"
."rnrn";//头信息
fputs ($fp, "$request");//向浏览器写信息(写出后,请求也会随之发送)
while (!feof($fp)){//如果还有需要写的接着写,一直到没有为止
$res[] = fgets($fp,1024);
}
$html = join("",$res);//连接字符串
fclose ($fp);//关闭套接字连接
$fp = file_put_contents("123cha.html",$html);//写入文件
echo "done";
<?php
$host = "www.123cha.com"; //定义变量
$referer = "http://".$host; //定义变量,并连接上一个串
$fp = fsockopen ($host, 80, $errno, $errstr, 30); // sock 到指定地址(即上面那个)。
if (!$fp){
echo "$errstr ($errno)<br>;n"; //返回空,输出信息
}else{
$request = "
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */"."*
Referer: http://$host
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: $host
Connection: Close"
."rnrn";
//构造一个get
fputs ($fp, "$request");//向server 发送get请求。
while (!feof($fp))
{
$res[] = fgets($fp,1024); //记录返回的信息。
}
$html = join("",$res);//将返回数组连成一个串。
fclose ($fp); //关闭 socket
$fp = file_put_contents("123cha.html",$html); //保存串。
echo "done"; //告诉你,嘿,完成了
}