Skip to content

Commit

Permalink
support zhihu answer
Browse files Browse the repository at this point in the history
  • Loading branch information
duty-machine committed Dec 4, 2020
1 parent 2647cd2 commit 91524e2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions websites/zhihu_answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let { URL } = require('url')
let fetch = require('node-fetch')
let { JSDOM } = require('jsdom')

module.exports = {
test(url) {
let parsed = new URL(url)
return parsed.hostname == 'www.zhihu.com'
},

async process(url) {
let res = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0'
}
})
let html = await res.text()
let document = new JSDOM(html).window.document

let title = document.querySelector('h1.QuestionHeader-title').textContent
let author = document.querySelector('.AnswerCard meta[itemProp="name"]').content
let content = document.querySelector('.AnswerCard .RichContent-inner')

return {
title,
author,
dom: content
}

},

samples: [
'https://www.zhihu.com/question/32059030/answer/1541280721'
]

}

0 comments on commit 91524e2

Please sign in to comment.