Crawling web page data with PHP

Source: Internet
Author: User
Recently, I developed a project in the company and cooperated with the client staff to Develop interfaces. The interface must receive the header information transmitted by the client staff, therefore, you cannot access this interface in the browser. Because the parameters you pass are incomplete, you recently thought of a method: simulate some data submission locally, in this case, I use the fsockopen function.

Recently, I developed a project in the company and cooperated with the client staff to Develop interfaces. The interface must receive the header information transmitted by the client staff, therefore, you cannot access this interface in the browser. Because the parameters you pass are incomplete, you recently thought of a method: simulate some data submission locally, in this case, I use the fsockopen function.

Recently, I developed a project in the company and cooperated with the client staff to Develop interfaces. The interface must receive the header information transmitted by the client staff, therefore, you cannot access this interface in the browser. Because the parameters you pass are incomplete, you recently thought of a method: simulate some data submission locally, at this time, I used the fsockopen function, which is quite good ..



 
Function index () {$ posturl = "XXX"; $ Did = '000000'; $ Key = md5 ($ Did. $ this-> Keym); $ ms = $ this-> require_by_socket ("Mm", "action", $ posturl, $ Did, $ Key ); // $ this-> display (); echo $ ms;} function require_by_socket ($ action, $ method, $ posturl, $ Did, $ Key) {$ fp = fsockopen ("$ posturl", 80, $ errno, $ errstr, 30); if (! $ Fp) {echo "$ errstr ($ errno)
\ N ";} else {// $ params = array ('did' => 1009, 'ver '=> '2017/123456', 'filmid' => 18 ); // $ post = http_build_query ($ params ); $ post = "did = 352110051958276 & ver = 199/22/20121222 & filmid = 18 & model = HTC & OS = and & pid = 1 & refresh = 1 "; // echo $ post; exit; $ header = "POST/service/index. php/$ action/$ method HTTP/1.1 \ r \ n "; $ header. = "Host: $ posturl \ r \ n"; $ header. = "Content-Type: application/x-www-form-urlencoded ". "\ r \ n"; $ Header. = "Content-Length :". strlen ($ post ). "\ r \ n"; $ header. = "Did: $ Did \ r \ n"; $ header. = "Key: $ Key \ r \ n"; // the header information is submitted here $ header. = "Connection: Close \ r \ n"; $ header. = $ post. "\ r \ n"; $ inheader = 1; fputs ($ fp, $ header); while (! Feof ($ fp) {$ result = fgets ($ fp, 1024 ); // only the returned data on the page is displayed when the request packet header is removed. if ($ inheader & ($ result = "\ n" | $ result = "\ r \ n" )) {$ inheader = 0;} // echo $ inheader; exit; if ($ inheader = 0) {$ info. = $ result ;}} fclose ($ fp); return $ info ;}}

Note: The above
$header .="Did:$Did\r\n";$header .="Key:$Key\r\n"; 

These parameters are actually the header parameter information that the developer wants. Then you can use the function to process the parameters so that you can get what you want.





We also share another method:


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.