superagent-cheerio is a small plugin that connects together SuperAgent and cheerio.
It came from using SuperTest for testing, and wanting easy access to cheerio for testing html/xml responses.
SuperAgent and cheerio are peer dependencies, you need to add them yourself.
$ npm install superagent cheerio superagent-cheerio
const request = require('superagent')
const superagentCheerio = require('superagent-cheerio')
const res = await request.get('https://www.google.co.uk').use(superagentCheerio())
console.log(res.$('h1').text())
// or promises
request.get('https://www.google.co.uk')
.use(superagentCheerio())
.then(res => {
console.log(res.$('h1').text())
})
const request = require('superagent')
const superagentCheerio = require('superagent-cheerio')
const agent = request.agent().use(superagentCheerio())
const res = await agent.get('https://www.google.co.uk')
console.log(res.$('h1').text())
// or promises
agent.get('https://www.google.co.uk').then(res => {
console.log(res.$('h1').text())
})
const request = require('superagent')
const superagentCheerio = require('superagent-cheerio')
const res = await request.get('https://www.google.co.uk').use(superagentCheerio({ xmlMode: true }))
console.log(res.$('h1').text())
// or promises
request.get('https://www.google.co.uk')
.use(superagentCheerio({ xmlMode: true }))
.then(res => {
console.log(res.$('h1').text())
})
Install dependencies:
$ npm install
Run tests:
$ npm test
MIT