jsdom
const jsdom = require('jsdom')
const {JSDOM} = jsdom
const fs = require('fs')
options = {
url : 'http://match.yuanrenxue.com/match/2',
referrer: 'http://match.yuansrenxue.com/match/2',
contentType: 'text/html',
userAgent : 'Messdfass/7800',
includeNodeLocations: true,
runScripts:'dangerously',
beforeParse(location) {
location.reload = function(){}
},
cookieJar:new jsdom.CookieJar(), //网站有setCookie的话,提前植入cookie
}
cookie = {}, url=''
options.cookieJar.setCookie(cookie, url, function () {
})
fs.readFile('./jjs.html', 'utf8', function (err, data){
const dom = new JSDOM(data, options);
console.log(dom.window.document.cookie)
dom.window.close()
});
proxy
//代理普通对象
var person = {
name: 14,
age: 444,
hobbies: [
'泡妞',
'看妹子'
]
}
var proxy = new Proxy(window, {
get(target, property){
// console.log('调用了target:', target)
console.log('调用了property: window的', property)
// Reflect.get(target, property)
return target[property]
},
set(target, property, value){
console.log('设置对象window', value)
target[property] = value
}
})
proxy.age
//代理window
window = global
window.a = '4444';
window.b = {
name: 'xiaosheng',
height: '200cm',
hobbies: [
'钓鱼',
'养鱼'
]
}
var proxy = new Proxy(window, {
get(target, property){
// console.log('调用了target:', target)
console.log('调用了property: window的', property)
// Reflect.get(target, property)
return target[property]
},
set(target, property, value){
console.log('设置对象window', value)
target[property] = value
}
})
proxy.a = 45
// console.log(b.length)
proxy.b.length
// ->设置对象window 45
// ->调用了property: window的 b
抠代码总结 的问题
抠代码的时候,如果代码里有this
,导出的话就不能直接导出了,要导出对象