cheerio 与 API 的离子创建

编程入门 行业动态 更新时间:2024-10-07 04:28:10

cheerio 与 API 的<a href=https://www.elefans.com/category/jswz/34/1755536.html style=离子创建"/>

cheerio 与 API 的离子创建

我正在创建一个离子应用程序。我将 Cheerio 与 Node.js 结合使用来抓取网站。我无法将整个数组返回到本地主机,它只返回第一个对象。我怎样才能返回整个数组?

这是抓取代码(scraper.js)

const request = require('request')
const cheerio = require('cheerio');

request('https://mywebsite', (error, response, html) => {
    if (!error && response.statusCode == 200) {
        const $ = cheerio.load(html)
        const art = $('article').each((i, el) => {
            const title = $(el)
                .find('.entry-title.mh-posts-grid-title')
                .text();
            const link = $(el)
                .find('a')
                .attr('href');
            const image = $(el)
                .find('.mh-thumb-icon.mh-thumb-icon-small-mobile')
                .text()
            const Arra = { title: [title], link: [link], image: [image] }
            exports.Arra = Arra

这是我导出数据的代码(document.js)

const express = require("express");
const ok = require('./ok')
const app = express();
const porta = '8000'



app.get('/', (req, res) => {
    res.send(ok.Arra);
})

app.listen(porta, () => {
    console.log(`Server ex ${porta}`);
});
回答如下:

一个不太合格的人提问和回答问题。

“谢谢”你。

╭∩╮(︶_︶)╭∩╮

更多推荐

cheerio 与 API 的离子创建

本文发布于:2024-05-30 14:59:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:离子   cheerio   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!