我创建了一个简单的 PHP 脚本来抓取 DuckDuckGo 的 html.duckduckgo.com。我希望抓取的不仅仅是结果的第一页。我使用的库仅支持 GET 请求,我似乎找不到将显示新结果页面的 GET 参数。
按“下一步”按钮向 DDG 发送 POST 请求,我尝试将 POST 请求中的参数添加到 GET 请求中,但没有成功。
知道如何找到 GET 参数来查看下一页结果吗?这样的事情还存在吗?
这是我当前的代码,我正在使用DiDOM。
<?php
require "../vendor/autoload.php";
use DiDom\Document;
$document = new Document('https://html.duckduckgo.com/html/?q=test', true);
$posts = $document->find('.result__url');
$links = [];
foreach($posts as $post) {
array_push($links, trim($post->text()));
}
$api = json_encode($links);
file_put_contents("links.json", $api);