|
1、功能:能够自动打开谷歌浏览器,输入快手玩家直播间id,观看快手用户直播的操作
2、const puppeteer = require('puppeteer');
const http = require('http');
const proxyChain = require('proxy-chain');
async function run() {
try {
var arguments = process.argv.splice(2);
console.log(arguments)
var args = {}
arguments.forEach(function(item,index) {
var arg = item.split('=');
args[arg[0]] = arg[1]
})
let port = args['--port']||8080;
let _args = [
'--window-size=1500,1000',
'--no-sandbox',
'--ignore-certificate-errors',
'--start-maximized',
'--disable-infobars',
'--remote-debugging-port=' + port,
'--user-data-dir=D://chrome/u' + port
]
if (args['proxy']) {
const proxy = args['--proxy']
_args.push(`--proxy-server=${proxy}`)
}
console.log(_args)
const browser = await puppeteer.launch({
args:_args,
headless: false,
executablePath: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
})
const page = (await browser.pages())[0];
if (args['--proxy-username']) {
var username = args['--proxy-username'];
var password = args['--proxy-pwd'];
await page.authenticate({username, password});
}
await page.setViewport({
width: 1500,
height: 1000,
deviceScaleFactor: 1,
});
await page.goto('https://live.kuaishou.com/');
//inout userinfo
await page.type('.pl-input-text','JJbeng77',{delay: 1});
await page.waitFor(1000);
await page.keyboard.press('Enter');
console.log(2)
//waiting page route
await page.waitFor(() => !!document.querySelector('.profile-card-user-info'));
await page.waitFor(1000);
//search the first user in list
await page.evaluate(()=>{
var user_list = document.querySelectorAll('.profile-card-user-info')
user_list[0].children[0].target = '_self'
user_list[0].children[0].click()
})
await page.waitFor(() => !!document.querySelector('.preview-video'));
await page.waitFor(1000);
//await page.waitFor('.preview-video');
//search the first view in list
await page.evaluate(()=>{
var view_list = document.querySelectorAll('.preview-video')
view_list[0].target = '_self'
view_list[0].click()
})
await page.waitFor(3000);
display(page)
initAction(page)
} catch (err) {
console.log(err.message);
}
}
async function initAction(page) {
var time = Math.round(Math.random()*1000)
setTimeout(function(){
var actions = Math.floor((Math.random()*2 + 1))
console.log(actions)
if (actions == 1) {
press(page)
} else {
moveTo(page)
}
initAction(page)
},time*100)
}
async function press(page) {
var enter_arr = ['L', 'W', 'Z', 'E']
var send_num = Math.floor(enter_arr.length * Math.random())
await page.keyboard.press(enter_arr[send_num])
}
async function message(page) {
await page.type('.pl-textarea', '已点', {delay: 2});
await page.waitFor(1000);
var button = await page.$('.submit-button');
await button.click();
}
async function moveTo(page) {
var x = Math.round(Math.random()*500)
var y = Math.round(Math.random()*700)
await page.mouse.move(x,y, function(){
})
}
async function display(page) {
await page.waitFor(() => !!document.querySelector('.player-video'));
await page.evaluate(()=>{
var player = document.querySelectorAll('.player-video')
player[0].height=10;
player[0].width=10;
})
await page.evaluate(()=>{
var category = document.querySelectorAll('.category')
category[0].style.display='none'
})
await page.evaluate(()=>{
var work = document.querySelectorAll('.more-recommend-live')
work[0].style.display='none'
})
await page.evaluate(()=>{
var work = document.querySelectorAll('.danmaku')
work[0].style.display='none'
})
await page.evaluate(()=>{
var live= document.querySelectorAll('.liveroom-sidebar')
live[0].style.display='none'
})
await page.evaluate(()=>{
var category = document.querySelectorAll('.work-list')
category[0].style.display='none'
})
}
run()
module.exports = {
run
}
|
|