下面的幻像代码给出了以下错误:
Assertion failed: (_consumed <= scratch_size), function _hb_coretext_shape, file src/hb-coretext.cc, line 764.
Abort trap: 6
我不明白我做错了什么。
var querystring = require('querystring')
var webpage = require('webpage')
var main = {}
/* global phantom, $, pass, user, url */
main.loginFormData = function (cb) {
var page = webpage.create()
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36'
page.open(url, function (status) {
page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function () {
var form = page.evaluate(function () {
return {
'formdata': $('form').serialize(),
'url': window.location.protocol + '//' + window.location.hostname + $('form').attr('action')
}
})
return cb(form)
})
})
}
main.loginLoginForm = function (data, cb) {
var formdata = querystring.parse(data.formdata)
formdata.login = user
formdata.password = pass
var payload = querystring.stringify(formdata)
var page = webpage.create()
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36'
page.open(data.url, 'post', payload, function (status) {
return cb(status)
})
}
main.loginFormData(function (data) {
console.log(JSON.stringify(data, null, 2))
main.loginLoginForm(data, function (data) {
console.log(JSON.stringify(data, null, 2))
phantom.exit()
})
})
这似乎只在调用page.settings.userAgent
时才会发生。
我转而使用promises,但错误仍然存在。
var Promise = require('bluebird')
var querystring = require('querystring')
var webpage = require('webpage')
var main = {}
var page = webpage.create()
page.settings.userAgent = ua
/* global phantom, $, pass, user, url, ua */
main.loginFormData = function () {
return new Promise(function (resolve, reject) {
page.open(url, function (status) {
if (status !== 'success') return reject(new Error(status))
page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function () {
var data = page.evaluate(function () {
return {
'formdata': $('form').serialize(),
'url': window.location.protocol + '//' + window.location.hostname + $('form').attr('action')
}
})
return resolve(data)
})
})
})
}
main.loginLoginForm = function (data) {
return new Promise(function (resolve, reject) {
var formdata = querystring.parse(data.formdata)
formdata.login = user
formdata.password = pass
var payload = querystring.stringify(formdata)
page.open(data.url, 'post', payload, function (status) {
if (status !== 'success') return reject(new Error(status))
return resolve()
})
})
}
main.loginFormData(page)
.then(function (data) {
// console.log(JSON.stringify(data, null, 2))
return main.loginLoginForm(page, data)
})
.then(function (data) {
// console.log(JSON.stringify(data, null, 2))
phantom.exit()
})
.catch(function () {
phantom.exit()
})
我正在使用的用户代理是:
var ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
在以下情况下成功运行:
page.settings.userAgent
page.settings.userAgent
作为默认值(Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1
)main.loginFormData
。在以下情况下意外运行: