Automation/app/Controllers/CLI/Crawl.php
2024-08-31 02:30:49 +09:00

32 lines
888 B
PHP

<?php
namespace App\Controllers\CLI;
use App\Libraries\CrawlerLibrary;
use App\Controllers\BaseController;
class Crawl extends BaseController
{
public function yamap()
{
try {
$crawler = new CrawlerLibrary("https://www.yamap16.com");
echo "Host-> " . $crawler->getHost() . "\n";
$links = $crawler->getLinks("/Board/List.aspx?id=free&ca=1", "a.list_subject");
echo var_export($links) . "\n";
$node = $crawler->getNode($links[8], "div.contents p");
echo $node->html() . "\n";
$images = $crawler->getImages($links[8], "img");
echo var_export($images) . "\n";
echo $crawler->getNode($links[8], "img")->attr("alt") . "\n";
// file_put_contents("test.jpg", $url);
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}