Curl Crawls Web content

Source: Internet
Author: User

<?Php
$curl=Curl_init();Initialize a Curl Object
$url= "Http://cart.jd.com/cart/cart.html?backurl=http://item.jd.com/176166.html&rid=0.9533184533 938766";
$header=Array();
$header[] = ' User-agent:5.0 (iPhone; U CPU iPhone os 4_3 like Mac os X; En-US) ';
$header[] = ' accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ';
$header[]= ' Accept-encoding:gzip,deflate ';
$header[]= '//Can add header content as needed ';
curl_setopt($curl,Curlopt_url,$url);Set the URL address you need to grab
curl_setopt($curl,Curlopt_header, $header Set Header
Curl_setopt ( $curl ,curlopt_returntransfer,1); Outputs the result back to the string
$str = Curl_exec ( $curl curl, request Web page
curl _close $curl Close URL request
return $str ; Returns or displays the result
?>

How to post data

Suppose we go to post a form to http://www.example.com/sendSMS.php
Submit content One is a phone number, a text message content
<?Php
$phoneNumber= ' 13598785110 ';
$message= ' This was a test message about the CURL to POST URL ';
$curlPost= ' Pnumber= '.$phoneNumber.' &message= '.UrlEncode($message).' &submit=send ';Stitching Request Parameters
$url= ' Http://www.example.com/sendSMS.php ';
$header[] = ‘........‘;
$curl=Curl_init();
curl_setopt($curl,Curlopt_url,$url);
curl_setopt($curl,Curlopt_header,$header);
curl_setopt($curl,Curlopt_returntransfer,1);
Curl_setopt ( $curl curlopt_post,1); Set the request mode to post
Curl_seropt ( $curl ,< Span class= "PLN" >curlopt_postfields, $curlPost Set post data
$data = Curl_exec (curl Curl_close ( $curl


?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.