Created
October 24, 2019 03:53
-
-
Save Karolass/ff8a98d73f03d72ec58afc9a0ff40ff8 to your computer and use it in GitHub Desktop.
簡易爬蟲
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cheerio = require('cheerio') | |
const request = require('./request') | |
const main = async () => { | |
const html = await request('https://s.weibo.com/top/summary?cate=realtimehot') | |
// console.log(html) | |
const $ = cheerio.load(html) | |
// console.log($) | |
const rows = $('#pl_top_realtimehot > table > tbody > tr') | |
// console.log(rows) | |
rows.each((i, element) => { | |
// console.log(i) | |
const rank = $(element).find('td.td-01.ranktop').text() | |
// console.log(rank.text()) | |
if (rank >= 1 && rank <= 10) { | |
const title = $(element).find('td.td-02 > a').text() | |
const count = $(element).find('td.td-02 > span').text() | |
console.log(rank, title, count) | |
} | |
}) | |
} | |
(async () => { | |
await main() | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request') | |
const rp = (url) => { | |
return new Promise((resolve, reject) => { | |
request(url, (error, response, body) => { | |
if (error) reject(error) | |
resolve(body) | |
}) | |
}) | |
} | |
module.exports = rp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment