在简单的html dom中按类别和ID选择,在Google搜索中不起作用

问题描述 投票:2回答:1

以下代码尝试通过class查找div不适用于google搜索结果,我也尝试过<< id >>。include('simple_html_dom.php'); $dom = file_get_html("https://www.google.com/search?q=best+mug"); $all_divs = $dom->find("div[class='g']"); foreach ($all_divs as $div) { echo $div->plaintext; }

以下代码尝试按类查找div,但不适用于google搜索结果,我也尝试过使用id。 include('simple_html_dom.php'); $ dom = file_get_html(“ https://www.google.com / ...
php regex web-scraping simple-html-dom
1个回答
1
投票
我认为使用XPath更好,这是使用XPath的代码示例:
© www.soinside.com 2019 - 2024. All rights reserved.