PhantomJS/CasperJS/playwright
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 UCBrowser/9.4.1.362 U3/0.8.0 Mobile Safari/533.1';
console.log('The user agent is ' + page.settings.userAgent);
// 生成一个随机 proxy tunnel
var seed = 1;
function random() {
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
const tunnel = random()*100;
//page.customHeaders = {
// "proxy-tunnel": tunnel,
//};
page.onResourceReceived = function(j) {
for (var i = 0; i < j.headers.length; ++i) {
console.log(j.headers[i].name + ': ' + j.headers[i].value);
}
};
page.open("http://httpbin.org/ip", {}, function(status) {
console.log('status> ' + status);
console.log(page.content);
setTimeout(function() {
phantom.exit();
}, 3000);
});
var casper = require('casper').create();
// 生成一个随机 proxy tunnel
var seed = 1;
function random() {
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
const tunnel = random()*1000;
casper.on('started', function () {
this.page.customHeaders = {
"User-Agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Connection" : "keep-alive",
"Proxy-Tunnel": tunnel
}
});
casper.start("http://httpbin.org/headers");
casper.then(function() {
console.log('First Page: ' + this.page.content);
});
casper.run();
const { chromium, webkit, firefox } = require('playwright');
(async () => {
const browser = await chromium.launch({
proxy: {
server: 'http://tunnel.hahado.cn:31111',
username: 'username',
password: 'password'
}
});
const page = await browser.newPage();
// Subscribe to 'request' and 'response' events.
page.on('request', request =>
console.log('>>', request.method(), request.url()));
page.on('response', response =>
console.log('<<', response.status(), response.url()));
await page.goto('https://httpbin.org/ip');
await browser.close();
})();
最后修改时间: 2 个月前