├── README.md ├── functions.php ├── get_keys.php ├── keys.txt ├── scraper.php └── validate_keys.php /README.md: -------------------------------------------------------------------------------- 1 | Works both on Windows and Linux. Tested on PHP 8.1.
2 | To run: 3 | ```properties 4 | php scraper.php 5 | ``` 6 | If the script is throwing errors, which it does if you are using a VPN, then use slow mode. 7 | 8 | ```properties 9 | php scraper.php -mode slow 10 | ``` 11 | 12 | The working keys are written in text files with the model name (gpt-4.txt, gpt-3.5-turbo.txt). 13 | 14 | -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | ([a-zA-Z0-9]{47})/'; 4 | $char = explode('--char=', $argv[1])[1]; 5 | $index = explode('--index=', $argv[2])[1]; 6 | $ch = curl_init(); 7 | curl_setopt($ch, CURLOPT_URL, "https://huggingface.co/search/full-text?q=s'k-$char&limit=100&skip=$index"); 8 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 9 | curl_setopt($ch, CURLOPT_TIMEOUT, 90); 10 | $output = curl_exec($ch); 11 | 12 | if ($output === false) 13 | throw new Exception(curl_error($ch)); 14 | preg_match_all($pattern, $output, $keys); 15 | $fd = fopen('keys.txt', 'a+'); 16 | foreach ($keys[0] as $key) 17 | { 18 | $key = str_replace('', '', $key); 19 | fwrite($fd, $key . PHP_EOL); 20 | } 21 | fclose($fd); 22 | -------------------------------------------------------------------------------- /keys.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasievt/huggingface-openai-key-scraper/56c30cf0e381c86884f1e2022f7a850f8b616cd9/keys.txt -------------------------------------------------------------------------------- /scraper.php: -------------------------------------------------------------------------------- 1 | 0) 6 | { 7 | $flag = array_shift($argv); 8 | switch ($flag) 9 | { 10 | case '-mode': 11 | { 12 | if (count($argv)===0) 13 | { 14 | echo "ERROR: No value was provided for flag $flag" . PHP_EOL; 15 | die(); 16 | } 17 | global $mode; 18 | $arg = array_shift($argv); 19 | switch ($arg) 20 | { 21 | case 'slow': 22 | { 23 | $mode = 'slow'; 24 | break; 25 | } 26 | default: 27 | echo "ERROR: No such mode: $arg" . PHP_EOL; 28 | die(); 29 | } 30 | } 31 | } 32 | } 33 | $chars = array_merge(range('a', 'z'), range('0', '9')); 34 | $path = __DIR__; 35 | foreach ($chars as $char) 36 | { 37 | for ($i=0; $i<=1000; $i+=100) 38 | { 39 | echo "Scraping: $char char" . ' ' . "Page № $i" . PHP_EOL; 40 | $command = ''; 41 | if ($OS) 42 | { 43 | $command = "php $path/get_keys.php --char=$char --index=$i > NUL:"; 44 | proc_open($command, [], $pipe); 45 | } 46 | else 47 | { 48 | $command = "php $path/get_keys.php --char=$char --index=$i > /dev/null &"; 49 | exec($command); 50 | } 51 | ifSlowModeDelay($mode); 52 | } 53 | } 54 | 55 | do { 56 | $flag = false; 57 | if (isScriptsRunning('get_keys.php')) 58 | pleaseWaitAnimation('Please wait'); 59 | else 60 | { 61 | echo PHP_EOL .'Done!' . PHP_EOL; 62 | $flag = true; 63 | } 64 | } 65 | while (!$flag); 66 | 67 | isFileEmpty('keys.txt'); 68 | $uniqueKeys = array_unique(explode(PHP_EOL, file_get_contents('keys.txt'))); 69 | cleanupFile('keys.txt'); 70 | 71 | foreach ($uniqueKeys as $key) 72 | { 73 | echo "Validating $key" . PHP_EOL; 74 | $command = ''; 75 | if ($OS) 76 | { 77 | $command = "php $path/validate_keys.php --key=$key > NUL:"; 78 | proc_open($command, [], $pipe); 79 | } 80 | else 81 | { 82 | $command = "php $path/validate_keys.php --key=$key > /dev/null &"; 83 | exec($command); 84 | } 85 | ifSlowModeDelay($mode); 86 | } 87 | 88 | do { 89 | $flag = false; 90 | if (isScriptsRunning('validate_keys.php')) 91 | pleaseWaitAnimation("Validating keys"); 92 | else 93 | { 94 | echo PHP_EOL . 'Done!' . PHP_EOL; 95 | $flag = true; 96 | } 97 | } 98 | while (!$flag); 99 | -------------------------------------------------------------------------------- /validate_keys.php: -------------------------------------------------------------------------------- 1 | $model, 17 | 'messages'=>[['role'=>'user', 'content'=>'Hi']], 18 | 'temperature'=>0.7])); 19 | if (curl_exec($ch)===false) 20 | throw new Exception(curl_error($ch)); 21 | if (isValidKey($ch)) 22 | { 23 | $fd = fopen("$model.txt", 'a+'); 24 | fwrite($fd, $key . PHP_EOL); 25 | fclose($fd); 26 | } 27 | } --------------------------------------------------------------------------------