How can scrape website via PHP that requires POST data?

后端 未结 2 1036
臣服心动
臣服心动 2021-01-15 09:14

I\'m trying to scrape a website that takes in POST data to return the correct page (sans POST it returns 15 results, with POST data it returns all results).

Currentl

2条回答
  •  执念已碎
    2021-01-15 09:57

    I think someone may look for code to replace XXXXXX. I use the following piece of code.

    $ch = curl_init();
    $timeout=5;
    $name=$_REQUEST['name'];
    $pass=$_REQUEST['pass'];
    $data = array('username' => '$name', 'password' => '$pass');
    $data=http_build_query($data);
    curl_setopt($ch,CURLOPT_URL,"superawsomesite.com"); 
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    

提交回复
热议问题