Created
September 8, 2016 12:48
-
-
Save tamanugi/a87b067c3e78007fc821a6bae626d867 to your computer and use it in GitHub Desktop.
SpookyJSでformの値に日本語を入力する ref: http://qiita.com/tamanugi/items/bcacdd2b412c6f944ee6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Spooky = require('spooky'); | |
var spooky = new Spooky({ | |
child: { | |
command: "node_modules/casperjs/bin/casperjs.exe", | |
transport: 'http' | |
}, | |
casper: { | |
logLevel: 'debug', | |
verbose: true | |
} | |
}, function (err) { | |
if (err) { | |
e = new Error('Failed to initialize SpookyJS'); | |
e.details = err; | |
throw e; | |
} | |
var links = []; | |
spooky.userAgent('Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0'); | |
spooky.start('https://www.google.co.jp'); | |
spooky.then(function () { | |
var payload = {q:'東京特許許可局'}; | |
this.fill('form[action="/search"]',payload, true); | |
}); | |
spooky.then(function(){ | |
links = this.evaluate(function(){ | |
var links = document.querySelectorAll('h3.r a'); | |
return Array.prototype.map.call(links, function(e) { | |
return e.getAttribute('href'); | |
}); | |
}); | |
}); | |
spooky.run(function(){ | |
this.emit('hello', links.join("\n")); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Spooky = require('spooky'); | |
var spooky = new Spooky({ | |
child: { | |
command: "node_modules/casperjs/bin/casperjs.exe", | |
transport: 'stdio' // ← ここを変更する | |
}, | |
casper: { | |
logLevel: 'debug', | |
verbose: true | |
} | |
}, function (err) { | |
if (err) { | |
e = new Error('Failed to initialize SpookyJS'); | |
e.details = err; | |
throw e; | |
} | |
var links = []; | |
spooky.userAgent('Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0'); | |
spooky.start('https://www.google.co.jp'); | |
spooky.then(function () { | |
var payload = {q:'東京特許許可局'}; | |
this.fill('form[action="/search"]',payload, true); | |
}); | |
spooky.then(function(){ | |
links = this.evaluate(function(){ | |
var links = document.querySelectorAll('h3.r a'); | |
return Array.prototype.map.call(links, function(e) { | |
return e.getAttribute('href'); | |
}); | |
}); | |
}); | |
spooky.run(function(){ | |
this.emit('hello', links.join("\n")); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node spooky-google.js | |
attempting to fetch form element from selector: 'form[action="/search"]' | |
Set "q" field value to 東京特許許可局 | |
submitting form to /search, HTTP GET | |
unable to submit form | |
https://ja.wikipedia.org/wiki/%E6%9D%B1%E4%BA%AC%E7%89%B9%E8%A8%B1%E8%A8%B1%E5%8F%AF%E5%B1%80 | |
http://www.tokkyonavi.com/qanda/basic/%E6%9D%B1%E4%BA%AC%E7%89%B9%E8%A8%B1%E8%A8%B1%E5%8F%AF%E5%B1%80.html | |
http://ja.uncyclopedia.info/wiki/%E6%9D%B1%E4%BA%AC%E7%89%B9%E8%A8%B1%E8%A8%B1%E5%8F%AF%E5%B1%80 | |
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12442622 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment