Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Last active October 6, 2020 05:51
Show Gist options
  • Select an option

  • Save remoharsono/72d60a93846de69ce4587ceb0f63dffd to your computer and use it in GitHub Desktop.

Select an option

Save remoharsono/72d60a93846de69ce4587ceb0f63dffd to your computer and use it in GitHub Desktop.

Revisions

  1. remoharsono renamed this gist Oct 6, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. remoharsono revised this gist Oct 6, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions answer-so-1.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    <?php
    // https://twitter.com/the_paTiku/status/1276075890812878848

    require 'vendor/autoload.php';

    use GuzzleHttp\Client;
  3. remoharsono created this gist Jun 25, 2020.
    32 changes: 32 additions & 0 deletions answer-so-1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <?php
    require 'vendor/autoload.php';

    use GuzzleHttp\Client;
    use GuzzleHttp\Exception\RequestException;
    use GuzzleHttp\Psr7\Request;

    use DiDom\Document;
    use DiDom\Query;

    $client = new \GuzzleHttp\Client();

    $base = 'https://resellers.tp-partner.pl';
    $url = $base . '/?action=sklepy&cmd=getCity&pr=zachodniopomorskie';

    $response = $client->request('GET', $url);
    $html = (string) $response->getBody();
    $document = new Document($html);
    $links = $document->find('.miasta > li > a::attr(href)');

    foreach($links as $link) {
    $url = $base . $link;
    $response = $client->request('GET', $url);
    $html = (string) $response->getBody();
    $document = new Document($html);
    $emails = $document->find('.email > a::attr(href)');

    if (!empty($emails)) {
    echo str_replace("mailto:", "", $emails[0]) . "\n";
    }
    }