云函数
调取网页内容
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const axios = require("axios")
const cheerio = require("cheerio")//加载本地数据
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
let res = await axios.get("http://huodong2.4399.com/gifts/al21hj_34.html?yx")
console.log(res)
let $ = cheerio.load(res.data)
let arr = []
$("first_title-3az8LFMb top_news_title a").each((v,k)=>{
console.log(v,k)
let obj = {
title: $(v).text()
}
arr.push(obj)
})
// console.log(res.data);
return arr;
}
getNews(){
wx.cloud.callFunction({
name:"getNews"
}).then(res=>{
console.log(res.result)
})
},