云函数不能使用“cheerio”吗?
发布于 5 年前 作者 klong 1525 次浏览 来自 问答
// 云函数入口文件
const cloud = require('wx-server-sdk')
 
cloud.init()
 
const rp = require('request-promise')
 
const cheerio = require('cheerio')
 
// 云函数入口函数
exports.main = async(event, context) => {
 
  const news_html = await rp('http://news.gdut.edu.cn/ArticleList.aspx?category=4').then((res) => {
    return res
  })
  const $ = cheerio.load(news_html)
  const news_title =  $('.evenrow a')
  console.log(news_title)
 
  return 666
}

为什么本地没问题,云函数就报错?

关于上传并部署:云端安装依赖,上传所有文件两种方式都试过了。

请问问题出来哪里?

补充:我rp访问的网址应该提供cookie的但是我没有提供,所以获取不到我想要的html,但是我刚刚测试其他正常的网页也是报同样的错误!!!

回到顶部