Webスクレイピングを学び、この例を使用してページからリンクを取得しようとしています。それを行うためのより良い方法はありますか、またはたとえば h1 を取得する最も簡単な方法は何ですか?
$html = file_get_contents('page.html');
//parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
//grab all the links on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
echo "<br />Link: $url";
}