Created
September 26, 2024 19:26
-
-
Save denisdemaisbr/08a0d8afd9e20b0161f5ee909394be0f to your computer and use it in GitHub Desktop.
Revisions
-
denisdemaisbr created this gist
Sep 26, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ <?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();