Skip to content

Instantly share code, notes, and snippets.

@denisdemaisbr
Created September 26, 2024 19:26
Show Gist options
  • Select an option

  • Save denisdemaisbr/08a0d8afd9e20b0161f5ee909394be0f to your computer and use it in GitHub Desktop.

Select an option

Save denisdemaisbr/08a0d8afd9e20b0161f5ee909394be0f to your computer and use it in GitHub Desktop.

Revisions

  1. denisdemaisbr created this gist Sep 26, 2024.
    43 changes: 43 additions & 0 deletions lotodicas.php
    Original 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();