forked from crispy-computing-machine/phpcrawl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCrawler.php
43 lines (37 loc) · 1.22 KB
/
MyCrawler.php
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
<?php
use PHPCrawl\PHPCrawler;
use PHPCrawl\PHPCrawlerDocumentInfo;
/**
* Class MyCrawler
*/
class MyCrawler extends PHPCrawler
{
/**
* @param PHPCrawlerDocumentInfo $DocInfo
* @return int|void
*/
public function handleDocumentInfo($DocInfo)
{
// Just detect linebreak for output ("\n" in CLI-mode, otherwise "<br>")..
if (PHP_SAPI === 'cli') {
$lb = "\n";
} else {
$lb = "<br />";
}
// Print the URL and the HTTP-status-Code
echo 'Page requested: ' . $DocInfo->url . ' (' . $DocInfo->http_status_code . ')' . $lb;
// Print the refering URL
echo 'Referer-page: ' . $DocInfo->referer_url . $lb;
// Print if the content of the document was be recieved or not
if ($DocInfo->received == true) {
echo "Content received: " . $DocInfo->bytes_received . " bytes" . $lb;
} else {
echo "Content not received" . $lb;
}
echo 'Error: ' . var_export($DocInfo->error_string, TRUE);
// Now you should do something with the content of the actual
// received page or file ($DocInfo->source), we skip it in this example
echo $lb;
flush();
}
}