【问题标题】:PHP DOM function file_get_html call after Complete Page load完成页面加载后调用 PHP DOM 函数 file_get_html
【发布时间】:2017-07-21 19:41:53
【问题描述】:

我们正在尝试从 PHP DOM 获取 url,但我们尝试获取的 webapge 具有功能(在页面加载后更改价格)所以现在我们需要 PHP Dom 函数 file_get_html 在此 onload 功能之后获取 HTML远程页面已完成。

$html = file_get_html('https://www.example.com');

// Find all article blocks
foreach($html->find('div.pad15 h4 a') as $article) {
    echo $article->innertext.'<br>';
}
foreach($html->find('p.sprc span.fb') as $pr){
        echo $pr->innertext.'<br>';
    }
$html->clear();
    unset($html);

【问题讨论】:

  • 这对于PHP Dom 是不可能的,你需要使用类似PhantomJS 的东西来允许运行JavaScript

标签: javascript php dom


【解决方案1】:

如果我回答正确的问题,你的问题是加载 js 后获取 html。不可能。因为php打开连接,一次性获取数据

【讨论】:

    【解决方案2】:

    关于你的问题的答案是“否”

    php 无法接收 javascript 呈现的结果。 javascript 在浏览器端运行,而 php 无法运行。

    另一种方法是用

    做任务

    http://phantomjs.org/

    var page = require('webpage').create();
    page.open('http://google.com', function () {
        console.log(page.content);
        phantom.exit();
    });
    

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 2015-01-28
      • 2022-07-06
      相关资源
      最近更新 更多