-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaniuse.php
More file actions
46 lines (37 loc) · 1.04 KB
/
caniuse.php
File metadata and controls
46 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Symfony\Component\DomCrawler\Crawler;
use LTDBeget\ConsoleTable\ConsoleTable;
$client = new Client([
'base_uri' => 'http://caniuse.com/',
'timeout' => 2.0,
]);
try {
$response = $client->get('/flexbox');
$crawler = new Crawler($response->getBody()->getContents());
$tbl = new LTDBeget\ConsoleTable\ConsoleTable();
$headers = [];
$items = $crawler->filter('.support-container > .support-list h4');
foreach ($items as $item) {
$headers[] = $item->nodeValue;
}
$tbl->setHeaders($headers);
$items = $crawler->filter('.support-container > .support-list ol');
foreach ($items as $item) {
foreach ($item->childNodes as $child) {
print_r($child);
}
}
/*$tbl->addRow(array('PHP', 1994));
$tbl->addRow(array('C', 1970));
$tbl->addRow(array('C++', 1983));*/
echo $tbl->getTable();
}
catch (RequestException $e) {
echo $e->getRequest();
if ($e->hasResponse()) {
echo $e->getResponse();
}
}