Using the PHP Curl Library, you can easily and effectively grab pages. You just need to run a script, then analyze the page you crawled, and then you can get the data you want in a program. Whether you want to take part of the data from a link, or take an XML file and import it into the database, the fear is simply to get the Web content, CURL is a powerful PHP library.
The common functions of the Curl Library in PHP (Client URL library function) are as follows:
- curl_close-closing a Curl session
- curl_copy_handle-Copy all the contents and parameters of a Curl connection resource
- curl_errno-returns a numeric number that contains the current session error information
- curl_error-returns a string containing the current session error message
- Curl_exec-performing a Curl session
- Curl_getinfo-gets the information for a Curl connection resource handle
- curl_init-initialization of a curl session
- curl_multi_add_handle-Adding a separate curl handle resource to a curl batch session
- curl_multi_close-closing a batch handle resource
- curl_multi_exec-parsing a Curl batch handle
- curl_multi_getcontent-returns the text stream of the obtained output
- Curl_multi_info_read-Gets the related transfer information for the currently resolved curl
- curl_multi_init-initializing a curl batch handle resource
- curl_multi_remove_handle-removing a handle resource from the Curl batch handle resource
- Curl_multi_select-get all the sockets associated with the CURL extension, which can and be "selected"
- curl_setopt_array-set session parameters as an array for a curl
- curl_setopt-setting session parameters for a curl
- curl_version-getting the version information about Curl
- The Curl_init () function Initializes a curl session, and the only parameter to the Curl_init () function is optional, representing a URL address.
- The function of the curl_exec () function is to perform a curl session, and the only argument is the handle returned by the Curl_init () function.
- The function of the Curl_close () function is to close a curl session, and the only argument is the handle returned by the Curl_init () function.
Basic examples
Post data
Accept two form fields, one for the phone number and one for the SMS content.
Using a proxy server
Analog Login
Simulate login Discuz program.
/I ', $contents, $matches); if (!empty ($matches)) {$formhash = $matches [1]; } else {die (' not found the Forumhash. '); }//post data, get cookie $cookie _file = dirname (__file__). '/cookie.txt '; $cookie _file = Tempnam ('/tmp '); $ch = Curl_init ($login _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $post _fields); curl_setopt ($ch, Curlopt_cookiejar, $cookie _file); Curl_exec ($ch); Curl_close ($ch); Take the cookie above to get the page content you need to log in to see $ch = Curl_init ($get _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 0); curl_setopt ($ch, Curlopt_cookiefile, $cookie _file); $contents = curl_exec ($ch); Curl_close ($ch); Var_dump ($contents);?>
http://www.bkjia.com/PHPjc/752496.html www.bkjia.com true http://www.bkjia.com/PHPjc/752496.html techarticle using the PHP Curl Library, you can easily and effectively grab pages. You just need to run a script, then analyze the page you crawled, then you can get what you want in a program ...