Skip to content

Instantly share code, notes, and snippets.

@denisdemaisbr
Created September 26, 2024 19:26
Show Gist options
  • Save denisdemaisbr/08a0d8afd9e20b0161f5ee909394be0f to your computer and use it in GitHub Desktop.
Save denisdemaisbr/08a0d8afd9e20b0161f5ee909394be0f to your computer and use it in GitHub Desktop.
download all files from lotodicas (php, fopen_url, xls, lottery)
<?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