@Andrei1231412

Не работает парсер с определенной странницей, почему?

Почему не работает парсинг с этой страницы ?? - https://soccer365.ru/games/921770/
Со страницы - https://soccer365.ru/ все ок

Не работает
$url = 'https://soccer365.ru/games/921770/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "GOOGLE");  // Обманочка
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
echo $output;


Работает
$url = 'https://soccer365.ru/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "GOOGLE");  // Обманочка
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
echo $output;


Как мне получить данные именно с этой страницы - https://soccer365.ru/games/921770/ ?
  • Вопрос задан
  • 189 просмотров
Пригласить эксперта
Ответы на вопрос 3
@Nujabes37
:DEATH
На, так работает)
$context = stream_context_create(
    [
        'http' => [
            'method'        => 'GET',
            'header'        => "path: /games/921770/\r\n" .
                               "User-agent: Mozilla/5.0 (Linux; Android 4.4.4; HM NOTE 1LTEW Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 MicroMessenger/6.0.0.54_r849063.501 NetType/WIFI\r\n",
            'ignore_errors' => true,
        ],
    ]
);

$request = file_get_contents(
    'https://soccer365.ru/games/921770/',
    false,
    $context
);

die(print_r($request));
Ответ написан
Комментировать
cesnokov
@cesnokov
<head>&nbsp;</head>
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "GOOGLE");  // Обманочка
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);

echo '<pre>';
print_r( curl_getinfo($ch) );
echo '</pre>';

curl_close($ch);
echo $output;


Да просто вы получаете код 301:
Array
(
    [url] => https://soccer365.ru/games/921770/
    [content_type] => text/html; charset=UTF-8
    [http_code] => 301
    [header_size] => 539
    [request_size] => 84
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.255368
    [namelookup_time] => 0.000614
    [connect_time] => 0.02999
    [pretransfer_time] => 0.19802
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => 0
    [starttransfer_time] => 0.25531
    [redirect_time] => 0
    [redirect_url] => https://soccer365.ru//soccer365.ru/live/match-etyir-1924-levski-smotret-onlayn/
    [primary_ip] => 51.15.25.134
    [certinfo] => Array
        (
        )
)


Используйте "redirect_url" и т.д.
Ответ написан
Комментировать
@Nc_Soft
CURLOPT_FOLLOWLOCATION
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 18:38
1500 руб./в час
19 апр. 2024, в 18:36
1500 руб./за проект
19 апр. 2024, в 18:36
30000 руб./за проект