2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

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');
    };
  });

結構な苦肉の策です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?