Help us understand the problem. What is going on with this article?

[PhantomJS]location.hrefを使ったリダイレクトにハマったら

More than 5 years have passed since last update.

HTTPステータスコードの301や302を使ったリダイレクトなら、一応ちゃんと処理してくれるのですが。JavaScriptのlocation.hrefなんかを使ったリダイレクトを書かれると、onLoadFinishedで謎のエラー終了を引き起こすことが、結構ある様子。

仕方ないので、万能ではないものの対応しておく。

function render_page(move_to) {
  var page = require('webpage').create();
  page.onNavigationRequested = function(url, type, willNavigate, main) {
    if (main && url != move_to) {
      page.close();
      render_page(url);
    };
  });
  page.open(move_to, function(status){
    if (status == 'success') {
      // do something
      page.render('path/to/snapshot.png');
    };
  });

結構な苦肉の策です。

nao58
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away