PHP Scraper从Google航班获取航班价格

时间:2020-05-29 11:40:37

标签: php web-scraping simple-html-dom

我正在尝试从Google航班中获取最便宜的航班价格,比方说此链接https://www.google.com/flights?hl=en#flt=LAX.LAS.2020-06-07 * LAS.LAX.2020-06-11; c:USD; e:1; sd:1; t :f

require 'simplehtmldom/simple_html_dom.php';
$link = 'https://www.google.com/flights?hl=en#flt=LAX.LAS.2020-06-07*LAS.LAX.2020-06-11;c:USD;e:1;sd:1;t:f';
$html = file_get_html($link);

$title = $html->find('title', 0);
$price = $html->find('.gws-flights-results__cheapest-price');

echo $title->plaintext."<br>\n";
if ($price) {
    echo $price[0]->plaintext."<br>\n";
}

但是我没有得到任何结果。我读过某个地方,因为Google航班上的DOM是由javascript生成的,因此需要运行javascript。但是我不确定如何用PHP做到这一点。我欢迎使用php或javascript的任何帮助或其他替代方法或更好的方法来从Google航班中抓取数据。

0 个答案:

没有答案
相关问题