Skip to content

Commit

Permalink
更新 爬取掘金 文章的接口地址
Browse files Browse the repository at this point in the history
  • Loading branch information
pubdreamcc committed Aug 18, 2020
1 parent 913fdf2 commit 6fff4d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 47 deletions.
61 changes: 19 additions & 42 deletions Node学习demo案例/Express/爬取掘金资源/app.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,36 @@
const express = require('express')
const cheerio = require('cheerio')
const superagent = require('superagent')
const app = express()
let result = []
app.use('/public', express.static('./public'))
app.engine('html', require('express-art-template'))
const express = require('express');
const cheerio = require('cheerio');
const superagent = require('superagent');
const app = express();
let result = [];
app.use('/public', express.static('./public'));
app.engine('html', require('express-art-template'));
let params = {
operationName:"",
query:"",
variables: {
first:20,
after: "",
order: "POPULAR"
},
extensions: {
query: {
id: "21207e9ddb1de777adeaca7a2fb38030"
}
}
category: "frontend",
limit: 30,
offset: 0,
order: "time"
}
function getInfo () {
superagent.post('https://web-api.juejin.im/query').send(params).set('X-Agent', 'Juejin/Web').end((err, res) => {
superagent.post('https://e.xitu.io/resources/gold')
.send(params)
.end((err, res) => {
if (err) {
return console.log(err)
}
const array1 = JSON.parse(res.text).data.articleFeed.items.edges
const num = JSON.parse(res.text).data.articleFeed.items.pageInfo.endCursor
result = array1.filter(item => {
return item.node.likeCount > 50
})
params.variables.after = num.toString()
superagent.post('https://web-api.juejin.im/query').send(params).set('X-Agent', 'Juejin/Web').end((err, res) => {
if (err) {
return console.log(err)
}
const array2 = JSON.parse(res.text).data.articleFeed.items.edges
const result2 = array2.filter(item => {
return item.node.likeCount > 50
})
result2.forEach(item => {
result.push(item)
})
})
result = res.body.data;
})
}
getInfo()
getInfo();
setInterval(() => {
getInfo()
}, 10*1000*60)
}, 10*1000*24);

app.get('/', (req, res, next) => {
res.render('index.html', {
result
})
});
})
app.listen(3000, () => {
console.log('running...')
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
<title>首页</title>
</head>
<body>
<div class="page-header">
<div class="page-header" style="margin: 50px 0">
<h2 style="text-align: center">爬取掘金前端优质文章</h2>
<p style="text-align: right; padding-right: 50px;">---&nbsp;&nbsp;&nbsp;按发表顺序前40篇点赞大于50的会出现在这里</p>
</div>
<ul class="list-group">
{{each result}}
<li class="list-group-item">
<a href="{{$value.node.originalUrl}}" target="_blank">{{$value.node.title}}</a>
<img data-v-7bf5f1fe="" src="https://b-gold-cdn.xitu.io/v3/static/img/zan.e9d7698.svg">
<span>{{$value.node.likeCount}}</span>
<a href="{{$value.originalUrl}}" target="_blank">{{$value.title}}</a>
<span>{{$value.user.username}}</span>
</li>
{{/each}}
</ul>
Expand Down

0 comments on commit 6fff4d4

Please sign in to comment.