Skip to content

Instantly share code, notes, and snippets.

@proclnas
Created May 3, 2016 06:51
Show Gist options
  • Save proclnas/ee7a3512e7243d47f134c025c675f564 to your computer and use it in GitHub Desktop.
Save proclnas/ee7a3512e7243d47f134c025c675f564 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: Rodrigo
* Date: 02/05/2016
* Time: 21:17
*/
require_once '/../vendor/autoload.php';
use PwebCrawler\PwebCrawler;
try {
$webCrawler = new PwebCrawler;
// GET
$response = $webCrawler->Uri('https://httpbin.org/get')
->getRequest()
->getHttpResponse();
// POST
$resposne = $webCrawler->Uri('https://httpbin.org/post')
->setPostPayload(
['PHP' => '7.0', 'Name' => 'Proc']
)->postRequest()
->getHttpResponse();
// Callback with dom element
$webCrawler->Uri('http://google.com')
->getRequest()
->setCallback(function($http_response, \DiDom\Document $dom, \PwebCrawler\PwebCrawler $pwc){
$elements = $dom->find('a');
foreach ($elements as $element)
echo $element->attr('href'), PHP_EOL;
echo "Total Response length: ", strlen($http_response), PHP_EOL;
});
} catch (Exception $e) {
var_dump($e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment