PHP code example of bitandblack / document-crawler
1. Go to this page and download the library: Download bitandblack/document-crawler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bitandblack / document-crawler example snippets
use BitAndBlack\DocumentCrawler\ContentCrawler\TitleCrawler;
use Symfony\Component\DomCrawler\Crawler;
$document = <<<HTML
<!doctype html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
HTML;
$crawler = new Crawler($document);
$titleCrawler = new TitleCrawler($crawler);
$titleCrawler->crawlContent();
// This will output `Test`.
echo $titleCrawler->getTitle();
use BitAndBlack\DocumentCrawler\HolisticDocumentCrawler;
$document = <<<HTML
<!doctype html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
HTML;
$holisticDocumentCrawler = new HolisticDocumentCrawler($document);
// Get all anchors:
$anchors = $holisticDocumentCrawler->getAnchors();
// Get all icons:
$icons = $holisticDocumentCrawler->getIcons();
// Get all images:
$images = $holisticDocumentCrawler->getImages();
// Get the language code:
$languageCode = $holisticDocumentCrawler->getLanguageCode();
// Get all meta tags:
$metaTags = $holisticDocumentCrawler->getMetaTags();
// Get the title:
$title = $holisticDocumentCrawler->getTitle();
use BitAndBlack\DocumentCrawler\HolisticDocumentCrawler;
$holisticDocumentCrawler = HolisticDocumentCrawler::createFromUrl('https://www.bitandblack.com');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.