송용우

Update getBJ function parameter

1 const axios = require("axios"); 1 const axios = require("axios");
2 const cheerio = require("cheerio"); 2 const cheerio = require("cheerio");
3 -let userid_test = "syw5141";
4 -const getHtml = async (userid) => {
5 - try {
6 - return await axios.get("https://www.acmicpc.net/user/" + userid);
7 - } catch (error) {
8 - console.log(error);
9 - }
10 -};
11 -
12 -getHtml(userid_test).then((html) => {
13 - let psList = [];
14 - const $ = cheerio.load(html.data);
15 - const $bodyList = $("div.panel-body").children();
16 3
17 - $bodyList.each(function (i) { 4 +exports.getBJ = function (userid) {
18 - if (i % 2 == 0) { 5 + const getHtml = async (userid) => {
19 - psList[i / 2] = { 6 + try {
20 - problem_number: $(this).children().text(), 7 + return await axios.get("https://www.acmicpc.net/user/" + userid);
21 - problem_title: $(this).next().children().text(), 8 + } catch (error) {
22 - }; 9 + console.log(error);
23 } 10 }
24 - }); 11 + };
25 12
26 - console.log(psList); 13 + getHtml(userid).then((html) => {
27 - return psList; 14 + let psList = [];
28 -}); 15 + const $ = cheerio.load(html.data);
16 + const $bodyList = $("div.panel-body").children();
29 17
30 -//body > div.wrapper > div.container.content > div.row > div:nth-child(2) > div:nth-child(3) > div.col-md-9 > div:nth-child(1) > div.panel-body 18 + $bodyList.each(function (i) {
19 + if (i % 2 == 0) {
20 + psList[i / 2] = {
21 + problem_number: $(this).children().text(),
22 + problem_title: $(this).next().children().text(),
23 + };
24 + }
25 + });
26 +
27 + console.log(psList);
28 + return psList;
29 + });
30 +};
......