Pagesource 使用 phantomjs 仅显示 html 个标签

Pagesource shows only html tags using phantomjs

我想使用 PHP 抓取一个网站,但是当我访问该网站并尝试获取页面源代码时,出现了这个错误:

<html><title>You are being redirected...</title>
<noscript>Javascript is required. Please enable javascript before you are allowed to see this page.</noscript>

因此,我尝试使用 phantom js 获取页面源:

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

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

但是使用幻影,我得到了这个结果:

<html><head></head><body></body></html>

我是不是用错了幻影?或者这个网站不能抓取?

我可以尝试通过哪种方式从页面获取数据?

站点有 javascript 重定向,但脚本在重定向完成之前尝试抓取 HTML,但什么也没有。需要等待一些时间 — 页面将在事件 onLoadFinished 之后构建或抓取内容,就像这样。试试下面的代码,它应该可以工作。

var page = require("webpage").create();
var homePage = "https://www.[real site name].com/";
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.2062'

page.open(homePage, function(status) {
    page.onLoadFinished = function(status){
        console.log(page.content);
        phantom.exit();
    };
});