Created
September 26, 2024 19:26
-
-
Save denisdemaisbr/08a0d8afd9e20b0161f5ee909394be0f to your computer and use it in GitHub Desktop.
download all files from lotodicas (php, fopen_url, xls, lottery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
download all xls files from a url | |
note: requires fopen_url enabled! | |
*/ | |
function downloadFile($fileUrl, $saveTo) | |
{ | |
$fileContent = file_get_contents($fileUrl); | |
if ($fileContent !== false) { | |
file_put_contents($saveTo, $fileContent); | |
echo "[ok] " . $saveTo . "\n"; | |
} else { | |
echo "[!!] " . $fileUrl . "\n"; | |
} | |
} | |
function extractXLSLinks($html) | |
{ | |
$pattern = '/<a[^>]+href="([^"]+\.xlsx?)"[^>]*>/i'; | |
preg_match_all($pattern, $html, $matches); | |
return $matches[1]; | |
} | |
function main() { | |
$url = 'https://www.lotodicas.com.br/lotofacil/downloads'; | |
$html = file_get_contents($url); | |
if ($html === false) { | |
die("[bogus] $url\n"); | |
} | |
$xlsLinks = extractXLSLinks($html); | |
foreach ($xlsLinks as $link) { | |
$fileUrl = 'https://www.lotodicas.com.br/' . $link; | |
$fileName = basename($fileUrl); | |
$savePath = $fileName; | |
downloadFile($fileUrl, $savePath); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment