简体   繁体   中英

How to get a value input from html returned of cURL?

I need to capture only the values of html inputs returned from curl_exec () function. This function returns the full html of the page, is there any way to take only the values of the inputs?

my code:

public function searchUser(Request $request){

    $data = $request->all();

      $cURL = curl_init('http://www.example.com/result.php');

      curl_setopt($cURL, CURLOPT_HEADER, false);
      curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

      $dados = array(
        'num_cnpj' => $data['cnpj'],
        'botao' => 'Consultar'

      );
      curl_setopt($cURL, CURLOPT_POST, true);
      curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);

      curl_setopt($cURL, CURLOPT_REFERER, 'http://www.example.com/index.php');

      $result = curl_exec($cURL);

      curl_close($cURL);

    return $result;

}

You could try using one of the many PHP dom parsers.

http://php.net/manual/en/domdocument.loadhtml.php

<?php
# Create a DOM parser object
$dom = new DOMDocument();

# Parse the HTML
# The @ before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
@$dom->loadHTML($result);

# Iterate over all the <input> tags
foreach($dom->getElementsByTagName('input') as $input) {
        # Show the attribute value
        echo $input->getAttribute('value');
        echo "<br />";
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM