Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

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

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

結構な苦肉の策です。

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
1
Help us understand the problem. What are the problem?