How php collects the Chinese proxy server network
This example describes how php collects the proxy server network in China. Share it with you for your reference. The details are as follows:
<? Php/*** collect the latest list of proxy servers in China */class proxy {/* list to be collected */public $ list; /* Save the proxy list path */public $ save_path = 'proxy.txt ';/* obtain the collection list */function get_list ($ page) {$ url = 'HTTP: // www.cnproxy.com/proxy (* pai.html '; // processing list $ this-> list = preg_replace ('/\ (\ * \)/', $ page, $ url ); return $ this-> list;}/* collect proxy content */function get ($ page) {$ this-> get_list ($ page ); $ file = stripslashes (file_get_contents ($ this-> list); $ zz = '/<Tr> <td> ([0-9 \.] +) <SCRIPT type = text \/javascript> document \. write \ (":" ([\ + a-z] + )\) <\/SCRIPT> <\/td> <td> [\ w] + <\/td> <td> [\ w \,] + <\/td>/is '; preg_match_all ($ zz, $ file, $ temp); unset ($ temp [0]); $ th = array ('Z ', 'M', 'k', 'l', 'D', 'x', 'I', 'w', 'Q', 'B '); $ 2nd = array (3, 4, 2, 9, 0, 5, 7, 6, 8, 1 ); foreach ($ temp [2] as $ k => $ v) {$ v = preg_replace ("/[\ +] +/", '', $ v ); $ s = str_replace ($ th, $ YY, $ v ); $ Re. = $ temp [1] [$ k]. ':'. $ s. "\ r \ n" ;}$ this-> save ($ re); return true;}/* save */function save ($ re) {return file_put_contents ($ this-> save_path, $ re, FILE_APPEND);}/* read */function read () {return file_get_contents ($ this-> save_path );}} // initialize the collection class $ p = new proxy; $ start = 1; $ end = 10; // control if ($ _ GET ['a'] = 'start ') {echo 'sending collection request'; echo '<meta http-equiv = "Refresh" content = "3; URL =? P = 1 "> ';} elseif (isset ($ _ GET ['P']) {$ I =$ _ GET ['P'] ++; if ($ I >=$ end + 1) {exit ('<meta http-equiv = "Refresh" content = "0; URL =? A = end "> ');} else {echo 'request list '. $ I. '> '. $ end; if ($ p-> get ($ I) {echo '<meta http-equiv = "Refresh" content = "3; URL =? P = '. $ _ GET ['P'] ++. '">' ;}} elseif ($ _ GET ['a'] = 'end') {echo 'collection finished ';} else {echo '<form> <input type = "hidden" name = "a" value = "start"/> <input type = "submit" value = "start collection "/> </form> ';}?>
I hope this article will help you with php programming.