송용우

Merge branch 'feature/crawling' into develop

This diff could not be displayed because it is too large.
...@@ -4,17 +4,21 @@ ...@@ -4,17 +4,21 @@
4 "main": "index.js", 4 "main": "index.js",
5 "license": "MIT", 5 "license": "MIT",
6 "dependencies": { 6 "dependencies": {
7 + "axios": "^0.19.2",
7 "bcrypt": "^4.0.1", 8 "bcrypt": "^4.0.1",
8 "body-parser": "^1.19.0", 9 "body-parser": "^1.19.0",
10 + "cheerio": "^1.0.0-rc.3",
9 "dotenv": "^8.2.0", 11 "dotenv": "^8.2.0",
10 "eslint-config-prettier": "^6.11.0", 12 "eslint-config-prettier": "^6.11.0",
11 "express": "^4.17.1", 13 "express": "^4.17.1",
12 "fs": "^0.0.1-security", 14 "fs": "^0.0.1-security",
15 + "iconv": "^3.0.0",
13 "joi": "^14.3.1", 16 "joi": "^14.3.1",
14 "jsonwebtoken": "^8.5.1", 17 "jsonwebtoken": "^8.5.1",
15 "mongoose": "^5.9.17", 18 "mongoose": "^5.9.17",
16 "morgan": "^1.10.0", 19 "morgan": "^1.10.0",
17 - "path": "^0.12.7" 20 + "path": "^0.12.7",
21 + "voca": "^1.4.0"
18 }, 22 },
19 "devDependencies": { 23 "devDependencies": {
20 "babel-eslint": "^10.1.0", 24 "babel-eslint": "^10.1.0",
......
1 +const axios = require("axios");
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 +
17 + $bodyList.each(function (i) {
18 + if (i % 2 == 0) {
19 + psList[i / 2] = {
20 + problem_number: $(this).children().text(),
21 + problem_title: $(this).next().children().text(),
22 + };
23 + }
24 + });
25 +
26 + console.log(psList);
27 + return psList;
28 +});
29 +
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