PHP 简单 HTML DOM 解析器 Returns 特定网站上没有任何内容

PHP Simple HTML DOM Parser Returns Nothing On a Specific Website

我想使用 PHP 简单 HTML DOM 解析器从 this page 中查找并显示 span#lblPricea.color-select-button selected,以及我在这方面写的代码是:

$html = file_get_html('https://meghdadit.com/product/75293/');

foreach ($html->find('span#lblPrice') as $e) {
    $price = $e->outertext;
    echo $price;
    break;
}
foreach ($html->find('a.color-select-button selected') as $e) {
    $color = $e->outertext;
    echo $color;
    break;
}

此代码适用于其他网站,但不幸的是 return 此网站没有任何结果。请检查此站点,看看是否发现问题。

你永远不会从这个 web-page 中获得任何价格内容,因为它加载了 JavaScript。如果你想实现这一点,你需要使用另一个抓取工具。 当您使用 SimpleHTMLDom 时,您的第一反应是回显您解析的 HTML 以查看库能够读取的内容!在这种情况下,甚至连 تومان 这个词都读不出来!

echo $html = file_get_html('https://meghdadit.com/product/75293/');

发生这种情况是因为您没有选择 span#lblPrice & a.color-select-button 回应

file_get_html('https://meghdadit.com/product/75293/');