You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP作业:如何用file_get_contents获取POST搜索结果第二页?

How to Fetch the Second Page of Search Results via POST Request

Got it, let's work through this. You've nailed the first page with your POST request, so grabbing the second page just boils down to figuring out what pagination parameter the site uses and adding it to your POST data.

Here's the step-by-step breakdown:

  1. Find the pagination parameter first

    • Manually search for "catalogue" on the site, then click through to the second page of results.
    • Open your browser's DevTools (press F12), head to the Network tab, and look for the POST request that loads the second page.
    • Check the Form Data section of that request—you’ll spot an extra parameter that wasn’t in your first-page call (common ones are page=2, p=2, or offset=XX depending on how the site paginates results).
  2. Update your POST data with the pagination parameter
    Let’s assume the site uses page as the pagination parameter (swap this out if your DevTools check shows a different key). Modify your $postdata to include this new parameter:

$postdata = http_build_query( array(
    'q' => 'catalogue',
    'submit' => 'searchbutton',
    'page' => 2 // Add the pagination parameter here
) );

$opts = array('http' => array(
    'method' => 'POST',
    'header' => 'Content-type: application/x-www-form-urlencoded',
    'content' => $postdata
) );

$context = stream_context_create($opts);
$result = file_get_contents('http://wiki.webo-facto.com/', false, $context);
  1. Test the adjusted request
    Run the modified code—this should pull the second page of your search results. If it doesn’t, double-check the exact parameter name and value from your DevTools capture (some sites use start instead of page, or expect an offset like offset=10 if each page displays 10 items).

内容的提问来源于stack exchange,提问作者kizawa tomaru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:38:56