-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape.php
25 lines (20 loc) · 884 Bytes
/
scrape.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$filename = "proxies-" . date('Y-m-d-H-i-s', time()) . ".txt";
$sources = file_get_contents("sources.txt");
// Credit: https://stackoverflow.com/questions/1483497/how-can-i-put-strings-in-an-array-split-by-new-line
$sources_array = preg_split("/\r\n|\n|\r/", $sources);
foreach($sources_array as $source){
scrape(file_get_contents($source), $filename);
}
function scrape($list, $output){
$splitlist = explode("\n", $list);
foreach($splitlist as $proxy){
$string = $proxy;
// Credit: https://stackoverflow.com/questions/11637555/regular-expressions-for-proxy-pattern
$pattern = '/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b:\d{2,5}/';
if (preg_match($pattern, $string, $match) ) {
file_put_contents($output, $match[0] . "\n", FILE_APPEND | LOCK_EX);
}
}
}
?>