Example 1: obtain the common page
For example, you can access the 54master Forum to capture all elements in the h3 mark on the homepage.
The code is as follows: |
Copy code |
$ Url = http://www.111cn.net; $ Contents = @ file_get_contents ($ url ); // Preg_match_all ("/<p class =" right forumcount "> (.*?) </P>/is ", $ contents, $ content ); Preg_match_all ("/Print_r ($ content [0]);
|
Example 2: Set the code IP address to collect data
Use file_get_contents and stream_context_create.
The code is as follows:
The code is as follows: |
Copy code |
$ AContext = array ( 'Http' => array ( 'Proxy' => 'tcp: // 192.168.0.2: 8080', // Set the proxy ip address and port number you want to use here. 'Request _ fulluri '=> true, ), ); $ CxContext = stream_context_create ($ aContext ); $ SFile = maid ("http://www.111cn.net", False, $ cxContext ); Echo $ sFile; |
The above code is applicable to normal conditions. However, if you need to log on to the target page or access through authentication information, you can add another code.
The code is as follows: |
Copy code |
$ Auth = base64_encode ('login: password'); // LOGIN: PASSWORD the name and PASSWORD of your account. $ AContext = array ( 'Http' => array ( 'Proxy' => 'tcp: // 192.168.0.2: 8080', // Set the proxy ip address and port number you want to use here. 'Request _ fulluri '=> true, 'Header' => "Proxy-Authorization: Basic $ auth ", ), ); $ CxContext = stream_context_create ($ aContext ); $ SFile = file_get_contents (http://www.111cn.net, False, $ cxContext ); Echo $ sFile; |
In this way, you can use a proxy to capture pages or files.