Classe PHP pour scraper des Proxies

Tue, 18 May 2021 12:22:01 Oletros

L'avantage d'une telle array en résultat, c'est qu'en premier élément se trouve le nombre de proxies et qu'en second élément se trouve les proxies en sous éléments. Ainsi il est bien plus simple ensuite d'itérer de sorte à récupérer aisément tous les proxies, puisque le nombre total est donné en même temps que la liste de proxies.


Voilà la classe en question :

<?php

class proxyScraperClass
{
        function setProxyScraper()
        {
                $proxyscraper = $this->proxyScraper();
                return $proxyscraper;
        }

        private function proxyScraper()
        {
                $curlProxies = curl_init();
                curl_setopt($curlProxies, CURLOPT_URL, "https://free-proxy-list.net/#list");
                curl_setopt($curlProxies, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curlProxies, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0");
                $htmlCurlProxies = curl_exec($curlProxies);
                curl_close($curlProxies);

                preg_match_all('/([0-9]{1,3}[.]{1}[0-9]{1,3}[.]{1}[0-9]{1,3}[.]{1}[0-9]{1,3}).{9}([0-9]{1,5})/', $htmlCurlProxies, $ips);

                $size = ( sizeof($ips, 1) - 3 ) / 3;

                $maxarr = $size - 1;

                $ipList['0'] = $size;

                for ($i = 0;  $i <= $maxarr; $i++)
                {
                       $ipList['1']["$i"] = $ips['1']["$i"] . ':' . $ips['2']["$i"];
                }

                return $ipList;

                }
}

L'appel de cette classe peut se faire, au plus simple, en considérant class.php comme étant le nom du fichier où se trouve la classe :

<?php

require_once('class.php');

$proxyScraper = new proxyScraperClass;
$resultProxyScraper = $proxyScraper->setProxyScraper();

print_r($resultProxyScraper);

Je choisis print_r au lieu de echo car le resultat est sous forme d'array.

Pour le résultat, ce sera de la forme :

Array ( [0] => 300 [1] => Array ( [0] => 185.132.133.188:1080 [1] => 200.69.81.198:58593 [2] => 95.160.17.142:40472 [3] => 46.55.161.162:46311 [4] => 187.60.36.164:53597 [5] => 119.28.118.116:1080 [6] => 185.132.133.173:1080 [7] => 147.75.113.110:8080 [8] => 103.86.155.78:34980 [9] => 185.132.178.141:1080 [10] => 103.57.70.248:31203 [11] => 93.170.115.179:52461 [12] => 118.97.53.99:31439 [13] => 139.162.11.82:3128 [14] => 67.60.137.219:35979 [15] => 37.145.184.104:8080 [16] => 51.38.71.101:8080 [17] => 185.132.178.135:1080 [18] => 212.56.218.90:60644 [19] => 134.119.205.164:8080 [20] => 5.196.132.121:3128 [21] => 192.99.191.235:1080 [22] => 185.37.55.156:808 [23] => 118.172.201.105:57900 [24] => 117.232.103.242:56594 [25] => 222.127.14.2:3128 [26] => 185.119.59.229:53281 [27] => 86.57.181.122:40881 [28] => 185.132.179.112:1080 [29] => 115.124.72.166:44885 [30] => 181.129.42.179:46129 [31] => 78.41.174.196:8088 [32] => 181.189.221.245:42407 [33] => 188.166.119.186:80 [34] => 101.255.63.22:43929 [35] => 139.255.94.123:42570 [36] => 192.99.191.239:1080 [37] => 212.180.196.130:36829 [38] => 101.255.75.125:55554 [39] => 36.67.52.99:53281 [40] => 103.100.79.17:48515 [41] => 116.254.100.165:46675 [42] => 197.210.186.38:34339 [43] => 170.210.236.1:57182 [44] => 195.211.30.115:47034 [45] => 193.233.9.167:41425 [46] => 103.26.245.190:43328 [47] => 93.39.228.188:3128 [48] => 185.132.178.139:1080 [49] => 185.132.133.213:1080 [50] => 101.255.64.193:36588 [51] => 181.112.216.82:51512 [52] => 191.97.6.140:9991 [53] => 170.239.46.177:58605 [54] => 93.170.95.127:49486 [55] => 125.209.116.146:46258 [56] => 190.217.39.174:8081 [57] => 36.67.149.171:53647 [58] => 190.200.172.246:3128 [59] => 41.216.230.148:36525 [60] => 179.43.98.186:23500 [61] => 110.172.135.234:43635 [62] => 182.160.124.26:47304 [63] => 103.86.141.13:39954 [64] => 62.85.52.95:53281 [65] => 186.148.168.94:33019 [66] => 181.112.56.2:53281 [67] => 43.225.164.59:37193 [68] => 111.93.246.34:8118 [69] => 103.21.160.156:35101 [70] => 185.132.179.115:1080 [71] => 185.132.179.113:1080 [72] => 95.79.55.196:53281 [73] => 80.73.90.18:3128 [74] => 159.203.14.149:4000 [75] => 36.85.74.4:3128 [76] => 43.245.202.120:46951 [77] => 5.196.132.123:3128 [78] => 101.109.143.71:36127 [79] => 85.175.216.32:53281 [80] => 191.36.244.230:51377 [81] => 103.87.207.188:46855 [82] => 175.41.44.51:52581 [83] => 103.81.114.182:53281 [84] => 23.101.2.247:8118 [85] => 41.169.162.194:40707 [86] => 103.76.44.190:42444 [87] => 109.70.201.97:53517 [88] => 217.30.78.54:53281 [89] => 178.54.209.120:58418 [90] => 140.227.236.31:8118 [91] => 103.66.176.97:51062 [92] => 110.74.196.235:46140 [93] => 217.30.64.26:53281 [94] => 91.211.122.23:39784 [95] => 103.221.254.44:56471 [96] => 187.190.237.8:32509 [97] => 169.57.157.146:80 [98] => 176.120.217.145:53281 [99] => 35.198.39.28:80 [100] => 103.94.0.180:53439 [101] => 161.202.226.194:8123 [102] => 185.132.179.114:1080 [103] => 190.82.82.146:60459 [104] => 36.37.183.214:30011 [105] => 185.189.199.75:23500 [106] => 190.97.209.74:60999 [107] => 182.53.206.26:45336 [108] => 186.225.43.49:57701 [109] => 87.241.241.183:40198 [110] => 188.163.170.130:41209 [111] => 93.190.137.63:8080 [112] => 34.213.71.81:3838 [113] => 103.250.156.22:30093 [114] => 35.240.164.91:8080 [115] => 35.240.133.122:8080 [116] => 159.192.197.166:8080 [117] => 5.58.56.142:8080 [118] => 198.98.51.240:8080 [119] => 50.233.42.98:51696 [120] => 59.126.148.127:8080 [121] => 51.68.141.240:3128 [122] => 88.199.82.189:38383 [123] => 191.96.42.82:3129 [124] => 190.29.101.62:44427 [125] => 23.237.23.73:3128 [126] => 192.99.191.234:1080 [127] => 103.196.210.18:8080 [128] => 60.53.207.49:8080 [129] => 51.79.142.25:8080 [130] => 45.175.239.254:999 [131] => 36.90.223.33:3128 [132] => 103.26.247.18:8081 [133] => 203.150.190.134:8080 [134] => 163.172.152.52:8811 [135] => 24.232.17.150:8080 [136] => 139.255.18.36:8080 [137] => 188.170.107.118:3128 [138] => 34.90.139.60:3128 [139] => 83.228.74.251:50800 [140] => 78.134.90.43:8080 [141] => 104.236.248.219:3128 [142] => 42.115.221.58:3128 [143] => 138.118.34.25:8080 [144] => 183.89.12.165:8080 [145] => 61.247.11.132:8080 [146] => 167.71.186.105:3128 [147] => 119.110.72.238:8080 [148] => 149.34.3.52:8080 [149] => 185.138.186.147:8080 [150] => 203.166.200.90:8080 [151] => 51.79.57.157:3128 [152] => 167.71.106.246:3128 [153] => 182.253.114.66:8080 [154] => 74.85.157.198:8080 [155] => 36.68.243.225:8080 [156] => 36.255.87.242:84 [157] => 191.7.219.62:9191 [158] => 167.114.197.123:3128 [159] => 27.72.29.159:8080 [160] => 45.224.97.103:999 [161] => 187.174.236.68:8080 [162] => 51.79.141.39:8080 [163] => 167.71.97.146:3128 [164] => 109.165.85.201:3128 [165] => 91.211.246.90:80 [166] => 43.245.184.238:8080 [167] => 41.67.12.71:8080 [168] => 41.215.74.234:47497 [169] => 36.66.127.99:8080 [170] => 105.112.8.53:3128 [171] => 49.49.17.69:8080 [172] => 217.19.209.253:8080 [173] => 188.187.0.158:8080 [174] => 201.49.238.86:20183 [175] => 36.90.154.205:80 [176] => 63.151.67.7:8080 [177] => 139.255.89.91:3128 [178] => 37.144.47.29:8080 [179] => 118.172.143.53:8080 [180] => 62.173.145.48:3128 [181] => 103.220.204.101:59570 [182] => 113.181.40.119:8080 [183] => 51.79.143.22:8080 [184] => 187.111.160.8:42579 [185] => 176.31.69.176:1080 [186] => 91.225.109.186:56617 [187] => 202.62.89.194:53281 [188] => 123.200.20.242:58847 [189] => 200.236.221.242:54336 [190] => 203.112.210.86:9090 [191] => 89.102.2.149:8080 [192] => 14.162.146.38:44910 [193] => 185.132.133.180:1080 [194] => 186.193.229.38:8080 [195] => 123.200.14.238:8080 [196] => 164.39.202.75:53281 [197] => 179.124.240.210:56869 [198] => 190.63.134.220:61535 [199] => 134.119.207.3:8080 [200] => 144.217.69.152:1080 [201] => 197.210.187.46:45753 [202] => 31.192.158.234:53281 [203] => 31.214.138.207:8080 [204] => 83.171.99.160:47114 [205] => 105.235.193.94:61386 [206] => 182.253.82.154:34207 [207] => 114.108.254.59:8080 [208] => 45.222.97.210:8080 [209] => 193.95.106.249:3128 [210] => 123.195.152.139:52295 [211] => 182.52.74.89:41334 [212] => 212.75.217.42:40479 [213] => 117.240.59.115:36127 [214] => 31.202.30.118:54547 [215] => 186.68.85.26:53281 [216] => 103.105.212.106:53281 [217] => 1.20.100.133:46755 [218] => 176.10.127.133:80 [219] => 46.235.71.241:8080 [220] => 178.217.168.77:37427 [221] => 43.243.141.126:53281 [222] => 45.6.136.38:53281 [223] => 185.99.64.75:35839 [224] => 203.123.255.142:30373 [225] => 139.5.68.98:80 [226] => 190.14.236.163:54694 [227] => 61.8.66.178:8080 [228] => 172.104.50.29:8080 [229] => 176.110.121.90:21776 [230] => 41.170.12.92:37444 [231] => 68.183.219.211:3128 [232] => 36.79.147.95:8080 [233] => 91.214.61.221:31321 [234] => 190.147.137.66:46876 [235] => 51.79.53.106:8080 [236] => 41.78.243.242:53281 [237] => 154.73.109.83:53281 [238] => 129.205.135.173:46696 [239] => 213.32.70.223:8000 [240] => 120.50.8.165:42255 [241] => 159.8.114.37:8123 [242] => 169.57.1.84:80 [243] => 36.89.27.235:53281 [244] => 47.88.245.100:8118 [245] => 187.141.164.242:31120 [246] => 182.160.127.53:39984 [247] => 80.78.75.59:38253 [248] => 195.211.162.116:58069 [249] => 186.151.160.174:59215 [250] => 93.190.137.146:8080 [251] => 106.104.12.180:80 [252] => 194.181.82.190:35447 [253] => 181.129.64.138:31768 [254] => 103.110.184.54:8080 [255] => 125.209.116.182:31653 [256] => 200.58.223.146:49801 [257] => 43.229.252.45:53281 [258] => 94.74.133.57:80 [259] => 91.197.174.108:8080 [260] => 182.253.204.155:57463 [261] => 186.42.124.130:65301 [262] => 164.68.98.168:3128 [263] => 87.99.93.100:43944 [264] => 103.220.206.110:59570 [265] => 150.129.250.28:60532 [266] => 144.48.109.178:56269 [267] => 212.90.168.150:52589 [268] => 110.74.199.68:54612 [269] => 118.174.232.239:39258 [270] => 197.255.244.70:53281 [271] => 59.91.127.29:53844 [272] => 162.223.89.94:8080 [273] => 81.161.61.110:55471 [274] => 45.226.48.38:60143 [275] => 200.24.84.4:39136 [276] => 195.182.22.92:49455 [277] => 41.193.238.242:8080 [278] => 212.154.58.106:35116 [279] => 36.67.27.189:47373 [280] => 50.233.228.147:8080 [281] => 177.46.141.143:36771 [282] => 86.125.112.183:47014 [283] => 27.121.85.194:8080 [284] => 36.89.190.213:44886 [285] => 61.247.178.218:50691 [286] => 190.217.104.130:9991 [287] => 69.10.47.1:8080 [288] => 170.233.97.239:8080 [289] => 202.43.166.202:8080 [290] => 103.81.77.11:83 [291] => 200.35.86.230:8080 [292] => 95.54.196.135:3128 [293] => 103.46.233.5:83 [294] => 109.245.229.229:80 [295] => 202.153.233.228:8080 [296] => 45.70.192.3:8080 [297] => 45.229.28.3:8080 [298] => 185.238.239.103:8090 [299] => 203.189.224.158:8080 ) ) 

Oletros