私はthis tutorialに続き、ウェブサイトの画像を作成しています。私が望むのは、イメージではなくウェブサイトのテキストを出力することです。URLのテキストを出力するようにPhantomJSを設定する方法
config.ru
ファイルは次のようになります。私は、コンテンツを出力するための例を見つけ
require 'sinatra/base'
require 'digest/md5'
class App < Sinatra::Base
get '/' do
return "to specifiy the rendered URL use \"?url=<some url>\"" unless params[:url]
digest = Digest::MD5.hexdigest(params[:url])
system(File.expand_path("~/app-root/data/phantomjs/bin/phantomjs"), File.expand_path("~/app-root/data/phantomjs/examples/rasterize.js"), params[:url], "public/#{digest}.png")
digest
end
end
run App
、ここでのコードは、content.js
です:
var webPage = require('webpage');
var page = webPage.create();
page.open('http://google.com', function() {
console.log(page.content);
phantom.exit();
});
ので、2つの質問があります。
-
は、
page.content
を印刷するにはどうすればよいですか?- クエリ文字列パラメータ
url
をcontent.js
ファイルに渡すにはどうすればよいですか?
回答ありがとうございました。 console.logでは、ウェブサイトのテキストコンテンツをブラウザに印刷しようとしています。言い換えれば、誰かがhttp://myurl.com/?url=google.comを訪問すると、そのサイトにあるすべてのテキストを表示したいと考えています。 –