PHP 使用分页页面上的 GET 请求解析网页file_get_contents


PHP Parse webpage with GET Request using file_get_contents on paginated page

我正在尝试使用file_get_contents解析网页。对于方法发布,我能够解析列表中的第一页。在此之后,页面内容通过分页列出。

我们如何使用 GET 请求解析分页页面的内容?

例如:http://sample.com/results?page=3

法典:

$data = array(
        'page' => 1
        );
    $opts = array(
      'http'=>array(
      'method'=> 'GET',
      'headers' => $http_response_header,
       'content' => http_build_query($data),
       'timeout' => 100
        )
    );
    $context = stream_context_create($opts);
    $listfile1 = file_get_contents("http://sample.com/results?",false, $context);

我得到分页页面的 0 条记录。

我能够使用上面列出的相同函数,定义了一个自定义函数,它破坏了分页。

然而,我也更改了网址。

       $listfile1 = file_get_contents("sample.com/results?page=".$number,false, $context);