ageent
03.10.2009, 09:31
Вообщем хочу написать парсер используя функцию fsockopen(). Пишу такой код.
<?php
$proxyhost = "78.153.210.191";
$proxyport = 80;
$http_request = "GET /moi-rasshirenija-joomla.html HTTP/1.1" . "\r\n";
$http_request .= "Host: www.ageent.ru" . "\r\n";
$http_request .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3";
$http_request .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" . "\r\n";
$http_request .= "Accept-Language: ru,en-us;q=0.7,en;q=0.3" . "\r\n";
$http_request .= "Accept-Encoding: gzip,deflate" . "\r\n";
$http_request .= "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7" . "\r\n";
$http_request .= "Keep-Alive: 300" . "\r\n";
$http_request .= "Connection: keep-alive" . "\r\n";
$http_request .= "Cache-Control: max-age=0". "\r\n\r\n";
$fp = fsockopen($proxyhost, $proxyport);
if ($fp) {
// передаем запрос
fwrite($fp,$http_request);
// читаем ответ
while (!feof($fp)) {
$http_response = fgets($fp, 1024);
if (preg_match("/^HTTP\/1\.\d (\d+) (.*)/", $http_response, $found)) {
$response_code = $found[1];
$response_text = $found[2];
break;
}
}
print_r($http_response);
}
else {
echo "2";
}
if ($response_code = 200) {
echo "1";
}
?>
В ответ мне приходит что соединении удалось и все!. Вопрос, а как тело документа получить-то?
<?php
$proxyhost = "78.153.210.191";
$proxyport = 80;
$http_request = "GET /moi-rasshirenija-joomla.html HTTP/1.1" . "\r\n";
$http_request .= "Host: www.ageent.ru" . "\r\n";
$http_request .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3";
$http_request .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" . "\r\n";
$http_request .= "Accept-Language: ru,en-us;q=0.7,en;q=0.3" . "\r\n";
$http_request .= "Accept-Encoding: gzip,deflate" . "\r\n";
$http_request .= "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7" . "\r\n";
$http_request .= "Keep-Alive: 300" . "\r\n";
$http_request .= "Connection: keep-alive" . "\r\n";
$http_request .= "Cache-Control: max-age=0". "\r\n\r\n";
$fp = fsockopen($proxyhost, $proxyport);
if ($fp) {
// передаем запрос
fwrite($fp,$http_request);
// читаем ответ
while (!feof($fp)) {
$http_response = fgets($fp, 1024);
if (preg_match("/^HTTP\/1\.\d (\d+) (.*)/", $http_response, $found)) {
$response_code = $found[1];
$response_text = $found[2];
break;
}
}
print_r($http_response);
}
else {
echo "2";
}
if ($response_code = 200) {
echo "1";
}
?>
В ответ мне приходит что соединении удалось и все!. Вопрос, а как тело документа получить-то?