-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2020-02-24 实现一个抽奖程序 #15
Comments
|
const axios = require('axios');
const BASE_URL = 'https://github.com/SlashLabTeam/2021questions/issues';
const reg1 = /issue\_(\d+)\_link/g
const reg2 = new RegExp("<a class=\"author link-gray-dark css-truncate-target width-fit\"[^>]+>([^<]+)</a>", 'g');
console.log("正在爬取网页");
axios.get(BASE_URL).then(({ data: html }) => {
console.log("正在获取选手");
const bucket = [], promisis = [], users = [];
html.replace(reg1, (_, i) => {
bucket.push(BASE_URL + `/${i}`)
})
bucket.forEach(url => {
promisis.push(axios.get(url).then(({ data: html }) => {
html.replace(reg2, (_, name) => {
if (!users.includes(name))
users.push(name);
});
}));
});
Promise.all(promisis).then(res => {
console.log(...users);
console.log('正在抽取幸运选手');
console.log(users[Math.ceil(Math.random() * users.length - 1)]);
}, e => {
console.log(e);
});
});
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
写一个爬虫,收集一下所有回复ISSUE做题的人,并且抽出一人中奖。
ps:不需要有UI,只需要有程序就好,不一定非要在浏览器中跑,node里面跑也可以。
The text was updated successfully, but these errors were encountered: