mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-30 20:50:44 +08:00
add core code
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
12
README.md
Normal file
12
README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Geek Auto Start Chat With Boss - BossGeekGo
|
||||
|
||||
一款可以帮助你在Boss直聘上**自动批量开聊Boss**的辅助脚本,基于Puppeteer。
|
||||
|
||||
A helper lets you can start a batch of chat sessions with human recruiter on **Bosszhipin**, based on Puppeteer.
|
||||
|
||||
## 使用方式
|
||||
1. 打开 Chrome / Edge,安装 EditThisCookie 扩展程序
|
||||
2. 打开 [Boss直聘](https://www.zhipin.com) 网站,在浏览器右上角找到 EditThisCookie 扩展程序图标,并点击
|
||||
3. 按下 EditThisCookie 扩展程序弹出气泡中的“导出Cookie”按钮(左数第三个按钮),此时将会把你在 Boss直聘 网站下所有Cookie复制到剪切板上
|
||||
4. 打开本项目中 runtime/boss-cookies.mjs 目录,把刚刚复制的Cookie粘贴给cookies变量
|
||||
5. 执行`npm start`,开始投递!祝新的一年,求职成功~
|
||||
203
main/index.mjs
Normal file
203
main/index.mjs
Normal file
@@ -0,0 +1,203 @@
|
||||
import puppeteer from 'puppeteer-extra';
|
||||
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
|
||||
|
||||
import bossCookies from '../runtime/boss-cookies.mjs'
|
||||
import targetCompanyList from '../runtime/target-company-list.mjs'
|
||||
|
||||
import {
|
||||
sleep,
|
||||
sleepWithRandomDelay
|
||||
} from './utils.mjs'
|
||||
|
||||
puppeteer.use(StealthPlugin())
|
||||
|
||||
if (!bossCookies?.length) {
|
||||
console.error('There is no cookies. you can save a copy with EditThisCookie extension.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const recommendJobPageUrl = `https://www.zhipin.com/web/geek/job-recommend`
|
||||
const pages = []
|
||||
globalThis.pages = pages
|
||||
|
||||
const expectCompanySet = new Set(targetCompanyList)
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: false,
|
||||
ignoreHTTPSErrors: true,
|
||||
defaultViewport: {
|
||||
width: 1440,
|
||||
height: 900 - 140,
|
||||
},
|
||||
devtools: true
|
||||
})
|
||||
|
||||
const page = await browser.newPage()
|
||||
sleep(2000).then(() => {
|
||||
page.bringToFront()
|
||||
})
|
||||
|
||||
//set cookies
|
||||
for(let i = 0; i < bossCookies.length; i++){
|
||||
await page.setCookie(bossCookies[i]);
|
||||
}
|
||||
|
||||
await page.goto(recommendJobPageUrl, { timeout: 0 })
|
||||
pages.push(page)
|
||||
|
||||
await sleepWithRandomDelay(2500)
|
||||
|
||||
const recommendJobLink = (await pages[0].$('[ka=header-job-recommend]'))
|
||||
await recommendJobLink.click()
|
||||
|
||||
while (true) {
|
||||
await sleepWithRandomDelay(3000)
|
||||
|
||||
const expectJobList = (await pages[0].evaluate(`
|
||||
document.querySelector('.job-recommend-search')?.__vue__?.expectList
|
||||
`)
|
||||
)
|
||||
|
||||
const expectJobTabHandlers = await pages[0].$$('.job-recommend-main .recommend-search-expect .recommend-job-btn')
|
||||
expectJobTabHandlers.shift()
|
||||
|
||||
// click first expect job
|
||||
await expectJobTabHandlers[0].click()
|
||||
await page.waitForResponse(
|
||||
response => {
|
||||
if (
|
||||
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/pc/recommend/job/list.json')
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
);
|
||||
await sleepWithRandomDelay(2000)
|
||||
|
||||
const { targetJobElProxy, targetJobIndex } = await new Promise(async (resolve) => {
|
||||
// job list
|
||||
const recommendJobListElProxy = await pages[0].$('.job-list-container .rec-job-list')
|
||||
|
||||
let jobListData = await pages[0].evaluate(
|
||||
`
|
||||
document.querySelector('.job-recommend-main')?.__vue__?.jobList
|
||||
`
|
||||
)
|
||||
let targetJobIndex = jobListData.findIndex(it => [...expectCompanySet].find(name => it.brandName.includes(name)))
|
||||
while (targetJobIndex < 0) {
|
||||
// fetch new
|
||||
const recommendJobListElBBox = await recommendJobListElProxy.boundingBox()
|
||||
const windowInnerHeight = await pages[0].evaluate('window.innerHeight')
|
||||
await pages[0].mouse.move(
|
||||
recommendJobListElBBox.x + recommendJobListElBBox.width / 2,
|
||||
windowInnerHeight / 2
|
||||
)
|
||||
let scrolledHeight = 0
|
||||
const targetHeight = 3000
|
||||
const increase = 40 + Math.floor(30 * Math.random())
|
||||
while (scrolledHeight < targetHeight) {
|
||||
scrolledHeight += increase
|
||||
await pages[0].mouse.wheel({deltaY: increase});
|
||||
await sleep(1)
|
||||
}
|
||||
|
||||
await sleep(3000)
|
||||
jobListData = await pages[0].evaluate(
|
||||
`
|
||||
document.querySelector('.job-recommend-main')?.__vue__?.jobList
|
||||
`
|
||||
)
|
||||
targetJobIndex = targetJobIndex = jobListData.findIndex(it => [...expectCompanySet].find(name => it.brandName.includes(name)))
|
||||
}
|
||||
|
||||
const recommendJobItemList = await recommendJobListElProxy.$$('ul.rec-job-list > li')
|
||||
resolve(
|
||||
{
|
||||
targetJobElProxy: recommendJobItemList[targetJobIndex],
|
||||
targetJobIndex
|
||||
}
|
||||
)
|
||||
})
|
||||
if (targetJobIndex > 0) {
|
||||
// scroll that target element into view
|
||||
await pages[0].evaluate(`
|
||||
const targetEl = document.querySelector("ul.rec-job-list").children[${targetJobIndex}]
|
||||
targetEl.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: ${Math.random() > 0.5 ? '\'center\'' : '\'end\''}
|
||||
})
|
||||
`)
|
||||
|
||||
await sleepWithRandomDelay(200)
|
||||
|
||||
// click that element
|
||||
await targetJobElProxy.click()
|
||||
await page.waitForResponse(
|
||||
response => {
|
||||
if (
|
||||
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/job/detail.json')
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
);
|
||||
await sleepWithRandomDelay(2000)
|
||||
}
|
||||
|
||||
const jobData = await pages[0].evaluate('document.querySelector(".job-detail-box").__vue__.data')
|
||||
|
||||
const startChatButtonInnerHTML = await pages[0].evaluate('document.querySelector(".job-detail-box .op-btn.op-btn-chat")?.innerHTML.trim()')
|
||||
if (startChatButtonInnerHTML === '立即沟通') {
|
||||
const startChatButtonProxy = await pages[0].$('.job-detail-box .op-btn.op-btn-chat')
|
||||
await startChatButtonProxy.click()
|
||||
|
||||
const addFriendResponse = await page.waitForResponse(
|
||||
response => {
|
||||
if (
|
||||
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/friend/add.json') && response.url().includes(`jobId=${jobData.jobInfo.encryptId}`)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
);
|
||||
try {
|
||||
const res = await addFriendResponse.json()
|
||||
|
||||
if (res.code !== 0) {
|
||||
console.err(res)
|
||||
break
|
||||
}
|
||||
} catch(err) {
|
||||
// console.warn(err)
|
||||
} finally {
|
||||
//#region TODO: temporary work with legacy logic
|
||||
await sleep(500)
|
||||
const continueChatButtonProxy = await pages[0].$('.greet-boss-dialog .greet-boss-footer .sure-btn')
|
||||
|
||||
await continueChatButtonProxy.click()
|
||||
//#endregion
|
||||
await sleepWithRandomDelay(2500)
|
||||
if (pages[0].url().startsWith('https://www.zhipin.com/web/geek/chat')) {
|
||||
await sleepWithRandomDelay(3000)
|
||||
|
||||
await Promise.all([
|
||||
pages[0].waitForNavigation(),
|
||||
pages[0].goBack(),
|
||||
])
|
||||
await sleepWithRandomDelay(1000)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
// ;await browser.close()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
})()
|
||||
9
main/utils.mjs
Normal file
9
main/utils.mjs
Normal file
@@ -0,0 +1,9 @@
|
||||
export function sleep (t) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, t)
|
||||
})
|
||||
}
|
||||
|
||||
export function sleepWithRandomDelay (base) {
|
||||
return sleep(base + Math.random()*1000)
|
||||
}
|
||||
19
package.json
Normal file
19
package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@bossgeekgo/geek-auto-start-chat-with-boss",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"description": "geek-auto-start-chat-with-boss",
|
||||
"module": "./main/index.mjs",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node ./main/index.mjs"
|
||||
},
|
||||
"author": "bossgeekgo",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.10",
|
||||
"puppeteer": "^21.6.1",
|
||||
"puppeteer-extra": "^3.3.6",
|
||||
"puppeteer-extra-plugin-stealth": "^2.11.2"
|
||||
}
|
||||
}
|
||||
1100
pnpm-lock.yaml
generated
Normal file
1100
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
3
runtime/boss-cookies.mjs
Normal file
3
runtime/boss-cookies.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
const cookies = [];
|
||||
|
||||
export default cookies;
|
||||
117
runtime/target-company-list.mjs
Normal file
117
runtime/target-company-list.mjs
Normal file
@@ -0,0 +1,117 @@
|
||||
export default [
|
||||
'青钱',
|
||||
'软通动力',
|
||||
'南天',
|
||||
'睿服',
|
||||
'中电金信',
|
||||
'佰钧成',
|
||||
'云链',
|
||||
'博彦',
|
||||
'汉克时代',
|
||||
'柯莱特',
|
||||
'拓保',
|
||||
'亿达信息',
|
||||
'纬创',
|
||||
'微创',
|
||||
'微澜',
|
||||
'诚迈科技',
|
||||
'法本',
|
||||
'兆尹',
|
||||
'诚迈',
|
||||
'联合永道',
|
||||
'新致软件',
|
||||
'宇信科技'
|
||||
]
|
||||
|
||||
// export default [
|
||||
// //
|
||||
// '抖音', '字节', '字跳', '有竹居', '脸萌', '头条',
|
||||
// //
|
||||
// '滴滴',
|
||||
// //
|
||||
// '网易',
|
||||
// //
|
||||
// '腾讯', '搜狗',
|
||||
// //
|
||||
// '京东',
|
||||
// //
|
||||
// '百度',
|
||||
// //
|
||||
// '度小满',
|
||||
// //
|
||||
// '爱奇艺',
|
||||
// //
|
||||
// '携程', '趣拿', '去哪儿',
|
||||
// //
|
||||
// '集度',
|
||||
// //
|
||||
// '理想',
|
||||
// //
|
||||
// '顺丰',
|
||||
// //
|
||||
// '讯飞',
|
||||
// //
|
||||
// '同程', '艺龙',
|
||||
// //
|
||||
// '贝壳', '链家',
|
||||
// //
|
||||
// '我爱我家',
|
||||
// //
|
||||
// '多点',
|
||||
// //
|
||||
// '金山', '小米', '猎豹',
|
||||
// //
|
||||
// '新浪', '微博',
|
||||
// //
|
||||
// '阿里', '蚂蚁', '飞猪', '高德', '乌鸫',
|
||||
// //
|
||||
// '美团', '三快',
|
||||
// //
|
||||
// '快手',
|
||||
// //
|
||||
// '映客',
|
||||
// //
|
||||
// '小红书', '行吟',
|
||||
// //
|
||||
// '奇虎', '360', '鸿盈', '奇富',
|
||||
// //
|
||||
// '亚信',
|
||||
// //
|
||||
// '启明星辰',
|
||||
// //
|
||||
// '奇安信',
|
||||
// //
|
||||
// '汽车之家',
|
||||
// //
|
||||
// '车好多', '瓜子',
|
||||
// //
|
||||
// '易车',
|
||||
// //
|
||||
// '昆仑万维', '闲徕',
|
||||
// //
|
||||
// '趣加',
|
||||
// //
|
||||
// '完美',
|
||||
// //
|
||||
// '马上消费',
|
||||
// //
|
||||
// '轻松',
|
||||
// //
|
||||
// '水滴',
|
||||
// //
|
||||
// '白龙马',
|
||||
// //
|
||||
// '58', '车欢欢', '五八', '红布林', '致美',
|
||||
// //
|
||||
// '美餐',
|
||||
// //
|
||||
// '知乎',
|
||||
// //
|
||||
// '易点云',
|
||||
// //
|
||||
// '搜狐',
|
||||
// //
|
||||
// '用友', '畅捷通',
|
||||
// //
|
||||
// '猿辅导', '小猿', '猿力',
|
||||
// ]
|
||||
Reference in New Issue
Block a user