上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖

node查询金价

[复制链接]
  • TA的每日心情
    无聊
    2023-11-2 17:37
  • 签到天数: 275 天

    [LV.8]以坛为家I

    114

    主题

    453

    回帖

    974

    积分

    荣誉开发者

    积分
    974

    荣誉开发者油中2周年卓越贡献生态建设者

    发表于 2024-4-23 12:36:49 | 显示全部楼层 | 阅读模式

    运行之前首先确保自己安装了node环境,需要安装cheerio库

    npm i cheerio

    然后执行代码即可

    const http = require('http');
    const cheerio = require('cheerio');
    
    function fetchData(url) {
      return new Promise((resolve, reject) => {
        http.get(url, (res) => {
          let data = '';
    
          res.on('data', (chunk) => {
            data += chunk;
          });
    
          res.on('end', () => {
            resolve(data);
          });
        }).on('error', (err) => {
          reject(err);
        });
      });
    }
    
    async function fetchAllData() {
      try {
        const response1 = await fetchData('http://www.dyhjw.com/brand/zhouliufu/');
        const response2 = await fetchData('http://dyhjw.com/brand/laofengxiang/');
        const response3 = await fetchData('http://www.dyhjw.com/brand/jinzhizun/');
        const $ = cheerio.load(response1);
        // html() 和 text() 都可以
        const divContent1 = $("body > div.main.w1020.float_clear > div.inx_l.float_clear > div.desc_txt.float_clear > div.desc_tit.fr.float_clear > div:nth-child(1) > p > span > font").text();
        console.log("今日周六福金价:"+divContent1+"克");
    
        const $1 = cheerio.load(response1);
        // html() 和 text() 都可以
        const divContent2 = $1("body > div.main.w1020.float_clear > div.inx_l.float_clear > div.desc_txt.float_clear > div.desc_tit.fr.float_clear > div:nth-child(1) > p > span > font").text();
        console.log("今日老凤祥金价:"+divContent2+"克");
    
        const $2 = cheerio.load(response1);
        // html() 和 text() 都可以
        const divContent3 = $2("body > div.main.w1020.float_clear > div.inx_l.float_clear > div.desc_txt.float_clear > div.desc_tit.fr.float_clear > div:nth-child(1) > p > span > font").text();
        console.log("今日金至尊金价:"+divContent3+"克");
    
        // console.log(response2);
        // console.log(response3);
        // 在这里处理两个请求的结果
      } catch (error) {
        console.error('请求遇到问题:', error);
      }
    }
    
    fetchAllData();
    

    image.png

    接脚本定制
    I frequently record, because want to leave something.
  • TA的每日心情
    开心
    2024-3-13 10:14
  • 签到天数: 211 天

    [LV.7]常住居民III

    296

    主题

    3919

    回帖

    3841

    积分

    管理员

    积分
    3841

    管理员荣誉开发者油中2周年生态建设者喜迎中秋油中3周年挑战者 lv2

    发表于 2024-4-23 15:14:33 | 显示全部楼层
    哥哥整个后台脚本接入https://sct.icodef.com/,每天通知
    上不慕古,下不肖俗。为疏为懒,不敢为狂。为拙为愚,不敢为恶。/ 微信公众号:一之哥哥
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-13 10:14
  • 签到天数: 211 天

    [LV.7]常住居民III

    296

    主题

    3919

    回帖

    3841

    积分

    管理员

    积分
    3841

    管理员荣誉开发者油中2周年生态建设者喜迎中秋油中3周年挑战者 lv2

    发表于 2024-4-24 14:22:03 | 显示全部楼层
    首饰金价不太靠谱,看看国际金价
    上不慕古,下不肖俗。为疏为懒,不敢为狂。为拙为愚,不敢为恶。/ 微信公众号:一之哥哥
    回复

    使用道具 举报

  • TA的每日心情
    无聊
    2023-11-2 17:37
  • 签到天数: 275 天

    [LV.8]以坛为家I

    114

    主题

    453

    回帖

    974

    积分

    荣誉开发者

    积分
    974

    荣誉开发者油中2周年卓越贡献生态建设者

    发表于 2024-4-24 14:56:34 | 显示全部楼层
    王一之 发表于 2024-4-24 14:22
    首饰金价不太靠谱,看看国际金价

    gg不给女朋友准备三金吗,我觉得首饰对gg有用
    接脚本定制
    I frequently record, because want to leave something.
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-13 10:14
  • 签到天数: 211 天

    [LV.7]常住居民III

    296

    主题

    3919

    回帖

    3841

    积分

    管理员

    积分
    3841

    管理员荣誉开发者油中2周年生态建设者喜迎中秋油中3周年挑战者 lv2

    发表于 2024-4-24 14:58:40 | 显示全部楼层
    wwwwwllllk 发表于 2024-4-24 14:56
    gg不给女朋友准备三金吗,我觉得首饰对gg有用

    470多的时候入了,还好入得早
    上不慕古,下不肖俗。为疏为懒,不敢为狂。为拙为愚,不敢为恶。/ 微信公众号:一之哥哥
    回复

    使用道具 举报

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表