14
15

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で引数を渡してサイトのHTMLソースとキャプチャをとってくるメモ

14
Last updated at Posted at 2014-09-08

備忘メモです

phantomJSの場合、nodeとは引数をとってくる方法が異なるようなのでメモ
とりあえずサンプル的に作ったので、UAとAccept-Languageは設定してません。。

起動方法

起動方法
$ phantomjs test.js "http://google.co.jp" "/tmp/google-top.jpg"

コマンド / 引数

Command phantomjs
1st 実行するスクリプト名
2nd 取得したいページのURL
3rd 画面キャプチャの保存先

サンプルスクリプト

test.js
var args = phantom.args;

url = args[0]
imgpath = args[1]

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

if (url == undefined) {
	phantom.exit();
}

page.viewportSize = {
	width : 1920,
	height : 1080
};
page.open(url, function start(status) {
	page.render(imgpath, {
		format : 'jpeg',
		quality : '80'
	});
	console.log(page.content);
	phantom.exit();
});
14
15
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
14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?