PHP code example of nizek / crawler
1. Go to this page and download the library: Download nizek/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/ */
nizek / crawler example snippets
$crawler->setUrl('https://example.com/sitemap.xml');
$urls = $crawler->parseXMLUrls();
foreach ($urls as $url) {
echo $url . PHP_EOL;
}
$crawler->setUrl('https://example.com');
$element = $crawler->getElementByTagName('h1');
echo $element->getText();
$crawler->setUrl('https://example.com');
$elements = $crawler->getElementsByTagName('a');
foreach ($elements as $element) {
echo $element->getAttribute('href') . PHP_EOL;
}
$crawler->setUrl('https://example.com');
$element = $crawler->getElementBySelector('img.img-thumb[alt="Apple iphone 12"]');
echo $element->getAttribute('src');
$crawler->setUrl('https://example.com');
$elements = $crawler->getElementsBySelector('list-item');
foreach ($elements as $element) {
echo $element->getText() . PHP_EOL;
}
$crawler->setUrl('https://example.com');
$element = $crawler->getElementByClassName('header');
echo $element->getText();
$crawler->setUrl('https://example.com');
$elements = $crawler->getElementsByClassName('list-item');
foreach ($elements as $element) {
echo $element->getText() . PHP_EOL;
}
$crawler->setUrl('https://example.com');
$content = $crawler->getPageContent();
echo $content;