Answer the question
In order to leave comments, you need to log in
Curl how to follow a link?
Why do I make a second request and display a new page, but the first one is issued?
<?
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;
Answer the question
In order to leave comments, you need to log in
Greetings!
Replace the loop as follows:
foreach ($links as $link) {
if ($link->innertext == 'Следующая страница') {
$targetLinkHref = htmlspecialchars_decode($link->href);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question