-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-hn.php
More file actions
49 lines (41 loc) · 1.51 KB
/
test-hn.php
File metadata and controls
49 lines (41 loc) · 1.51 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
47
48
49
<?php
use Scrawler\Bootstrap;
use Scrawler\Scrawler;
require_once __DIR__ . "/vendor/autoload.php";
Bootstrap::init();
$html = '<tr class="athing submission" id="45947810"><td align="right" valign="top" class="title"><span class="rank">1.</span></td><td valign="top" class="votelinks"><center><a id="up_45947810"><div class="votearrow" title="upvote"></div></a></center></td><td class="title"><span class="titleline"><a href="https://www.zigbook.net">Open-source Zig book</a><span class="sitebit comhead"> (<a href="from?site=zigbook.net"><span class="sitestr">zigbook.net</span></a>)</span></span></td></tr>';
$scrawler = new Scrawler();
// Test 1: Simple selector
echo "Test 1: Simple tr.athing selector\n";
$schema1 = [
"threads" => [
"tr.athing" => [
"title" => "span.titleline a",
],
],
];
$result1 = $scrawler->scrape($html, $schema1, true);
var_dump($result1);
// Test 2: With all fields
echo "\n\nTest 2: Full schema\n";
$schema2 = [
"threads" => [
"tr.athing" => [
"id" => "@id",
"rank" => "span.rank",
"title" => "span.titleline a",
"url" => "span.titleline a@href",
"site" => "span.sitestr",
],
],
];
$result2 = $scrawler->scrape($html, $schema2, true);
var_dump($result2);
// Test 3: Try with table wrapper
echo "\n\nTest 3: Try direct element\n";
$schema3 = [
"title" => "span.titleline a",
"url" => "span.titleline a@href",
];
$result3 = $scrawler->scrape($html, $schema3, true);
var_dump($result3);