-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup.php
More file actions
36 lines (29 loc) · 982 Bytes
/
group.php
File metadata and controls
36 lines (29 loc) · 982 Bytes
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
<?php
/*
* This file is part of the ixnode/php-web-crawler project.
*
* (c) Björn Hempel <https://www.hempel.li/>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
declare(strict_types=1);
require dirname(__DIR__).'/vendor/autoload.php';
use Ixnode\PhpWebCrawler\Output\Field;
use Ixnode\PhpWebCrawler\Output\Group;
use Ixnode\PhpWebCrawler\Source\Url;
use Ixnode\PhpWebCrawler\Value\XpathTextNode;
$url = 'https://en.wikipedia.org/wiki/Pirates_of_the_Caribbean:_The_Curse_of_the_Black_Pearl';
$html = new Url(
$url,
new Group(
'group',
new Field('title', new XpathTextNode('//*[@id="firstHeading"]/i')),
new Field('directed_by', new XpathTextNode('//*[@id="mw-content-text"]/div/table[1]//tr[3]/td/a'))
)
);
try {
echo $html->parse()->getJsonStringFormatted() . PHP_EOL;
} catch (Exception $e) {
echo 'Error: '.$e->getMessage().PHP_EOL;
}