无法使用phantomjs下载HTML [英] Can not download html with phantomjs

查看:168
本文介绍了无法使用phantomjs下载HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有3个不同的文件,布局是

I have 3 different files in my project and the layout is

  • phantomjs
  • -> phantomjs.js
  • -> phantomjs.exe
  • index.php

index.php:

index.php:

$phantom_script = dirname(__FILE__). '\phantomjs\phantomjs.js';

$response =  exec ('\phantomjs\phantomjs.exe' . $phantom_script);

echo $response;

phantomjs \ phantomjs.js

phantomjs\phantomjs.js

var webPage = require('webpage');
var page = webPage.create();

page.open('http://www.google.com', function(status) {
   console.log(page.content);
   phantom.exit();
});

推荐答案

您的用法oh phantomjs根据文档是正确的. http://phantomjs.org/api/webpage/property/content.html

your usage oh phantomjs is correct according to the documentation. http://phantomjs.org/api/webpage/property/content.html

php exec方法仅返回最后一行. 也许那条线是空白. http://php.net/manual/fr/function.exec.php

php exec method returns the last line only. Maybe that line is a white space. http://php.net/manual/fr/function.exec.php

您应该有一个通过引用发送的第二个参数& $ output.这是一个包含整个输出的数组.

You shall have a seond parameter &$output, sent by reference. It is an array containing the entire output.

稍后可能会遇到的问题,在尝试读取DOM文档内容之前,可能需要对内容进行评估.例如,使用HTML标记的innerHTML,即:$('html').html();

A problem you may face later, the content could need be to evaluated before you try to read it s DOM document content. Using for example innerHTML of HTML tag, ie: $('html').html();

如果该页面没有jquery,则可以包含它,请参见以下示例,

If the page does not have jquery, you may include it, see this example, https://github.com/ariya/phantomjs/blob/master/examples/phantomwebintro.js

还请注意,Google可能会积极希望不要让用户抓取并保存他们的搜索结果.不确定.

Note also that google may actively desire to not let users scrap and save their search results. Not sure about that.

这篇关于无法使用phantomjs下载HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆