使用该函数抓取的网页在最顶部会有一个6d4c这样的字符,这个字符怎么来的,搞不懂?function urlget ($url, $data, $headers) { $items = @parse_url($url);
if (!$items || $items['scheme'] !== 'http') {
return false;
} $host = $items['host'];
if (!$host) {
return false;
} $port = $items['port'];
if (!$port) {
$port = 80;
}
$path = $items['path'];
if (!$path) {
$path = '/';
} $s = @fsockopen($host, $port, &$e, &$t, 20);
if ($s === false) {
return false;
} $location = $path;
if ($items['query']) {
$location .= '?' . $items['query'];
} if ($data) {
$first_line = 'POST ' . $location . ' HTTP/1.1';
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
$headers['Content-Length'] = strval(strlen($data));
}else {
$first_line = 'GET ' . $location . ' HTTP/1.1';
} $headers['HOST'] = $host; $request_header = "$first_line\r\n";
foreach ($headers as $key => $val) {
$request_header .= "$key: $val\r\n";
} fputs($s, $request_header . "\r\n"); if ($data) {
fputs($s, $data);
} $source_read = '';
$header_found = false;
$status = socket_get_status($s);
while ($status['timed_out'] != true && !feof($s)) {
socket_set_timeout($s, 5);
$source_read .= fgets($s, 1024);
if ($header_found == false && substr(&$source_read,-4,4) == "\r\n\r\n") {
$response_header = substr( $source_read, 0, strlen($source_read)-2 );
$header_found = true;
$source_read = '';
}
$status = socket_get_status($s);
}
$response_body = $source_read; return array ($response_header, $response_body);}$a = urlget('http://www.molyx.com/index.php','',array('Content-Type' => 'text/xml;charset=utf-8'));
$fp = fopen('login.html','wb+');
fwrite($fp,$a[1]);
fclose($fp);
if (!$items || $items['scheme'] !== 'http') {
return false;
} $host = $items['host'];
if (!$host) {
return false;
} $port = $items['port'];
if (!$port) {
$port = 80;
}
$path = $items['path'];
if (!$path) {
$path = '/';
} $s = @fsockopen($host, $port, &$e, &$t, 20);
if ($s === false) {
return false;
} $location = $path;
if ($items['query']) {
$location .= '?' . $items['query'];
} if ($data) {
$first_line = 'POST ' . $location . ' HTTP/1.1';
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
$headers['Content-Length'] = strval(strlen($data));
}else {
$first_line = 'GET ' . $location . ' HTTP/1.1';
} $headers['HOST'] = $host; $request_header = "$first_line\r\n";
foreach ($headers as $key => $val) {
$request_header .= "$key: $val\r\n";
} fputs($s, $request_header . "\r\n"); if ($data) {
fputs($s, $data);
} $source_read = '';
$header_found = false;
$status = socket_get_status($s);
while ($status['timed_out'] != true && !feof($s)) {
socket_set_timeout($s, 5);
$source_read .= fgets($s, 1024);
if ($header_found == false && substr(&$source_read,-4,4) == "\r\n\r\n") {
$response_header = substr( $source_read, 0, strlen($source_read)-2 );
$header_found = true;
$source_read = '';
}
$status = socket_get_status($s);
}
$response_body = $source_read; return array ($response_header, $response_body);}$a = urlget('http://www.molyx.com/index.php','',array('Content-Type' => 'text/xml;charset=utf-8'));
$fp = fopen('login.html','wb+');
fwrite($fp,$a[1]);
fclose($fp);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货