@felsme

Curl как перейти по ссылке?

Почему я делаю второй запрос и вывожу уже новую страницу, а выдаётся первая ?
<? 
require_once('simple_html_dom.php');
$url = 'https://ru.wikipedia.org/wiki/Категория:Компьютерные_игры_по_алфавиту';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
$html = curl_exec($ch);

$html = str_get_html($html);
$links = $html->find('a');
$targetLinkHref = null;
foreach ($links as $link) {
  if ($link->innertext == 'Следующая страница') {
    $targetLinkHref = $link->href;
  }
}

$targetLinkHref = "https://ru.wikipedia.org$targetLinkHref";
curl_setopt($ch, CURLOPT_URL, $targetLinkHref);
$html = curl_exec($ch);
curl_close($ch);
echo $html;
  • Вопрос задан
  • 1106 просмотров
Решения вопроса 1
@Kozlovdaniil
Php/Python developer
Приветствую!
Цикл заменить следующим образом:
foreach ($links as $link) {
    if ($link->innertext == 'Следующая страница') {
        $targetLinkHref = htmlspecialchars_decode($link->href);
    }
}


Там в url затёсывается
&amp;
вместо &
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы