Showing
1 changed file
with
7 additions
and
7 deletions
| 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"; | 3 | + |
| 4 | -const getHtml = async (userid) => { | 4 | +exports.getBJ = function (userid) { |
| 5 | + const getHtml = async (userid) => { | ||
| 5 | try { | 6 | try { |
| 6 | return await axios.get("https://www.acmicpc.net/user/" + userid); | 7 | return await axios.get("https://www.acmicpc.net/user/" + userid); |
| 7 | } catch (error) { | 8 | } catch (error) { |
| 8 | console.log(error); | 9 | console.log(error); |
| 9 | } | 10 | } |
| 10 | -}; | 11 | + }; |
| 11 | 12 | ||
| 12 | -getHtml(userid_test).then((html) => { | 13 | + getHtml(userid).then((html) => { |
| 13 | let psList = []; | 14 | let psList = []; |
| 14 | const $ = cheerio.load(html.data); | 15 | const $ = cheerio.load(html.data); |
| 15 | const $bodyList = $("div.panel-body").children(); | 16 | const $bodyList = $("div.panel-body").children(); |
| ... | @@ -25,6 +26,5 @@ getHtml(userid_test).then((html) => { | ... | @@ -25,6 +26,5 @@ getHtml(userid_test).then((html) => { |
| 25 | 26 | ||
| 26 | console.log(psList); | 27 | console.log(psList); |
| 27 | return psList; | 28 | return psList; |
| 28 | -}); | 29 | + }); |
| 29 | - | 30 | +}; |
| 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 | ... | ... |
-
Please register or login to post a comment