javascript - 在 node.js 中显示为 html
问题描述
let request = require('request');
let cheerio = require('cheerio');
const $url = 'http://kradata.kra.co.kr:8082/service/api15/getOpenDataList';
const $KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx';
const $meet = '1';
const $hr_no = '037703';
const $api_url = $url + '?meet=' + $meet + '&hr_no=' + $hr_no + '&ServiceKey=' + $KEY;
console.log($api_url);
request($api_url, function(err, res, body) {
$ = cheerio.load(body);
$('item').each(function(idx){
let no1 = $(this).find('hrName').text();
let no2 = $(this).find('winRateT').text();
let no3 = $(this).find('qnlRateT').text();
let no4 = $(this).find('winRateY').text();
let no5 = $(this).find('recentRcDist').text();
let no6 = $(this).find('chaksunT').text();
let no7 = $(this).find('chaksunY').text();
let no8 = $(this).find('chaksun_6').text();
console.log(`경주마 이름 : ${no1} \n 통산 승률: ${no2}, 통산 복승률: ${no3}, 최근 1년 승률: ${no4} \n 최근경주거리: ${no5}, 통산착순상금: ${no6}, 최근1년착순상금: ${no7}, 최근6개월수득상금: ${no8}`);
});});
如何在 html 中显示 console.log 中的数据?
解决方案
如果你想显示你正在console.log()
阅读的文本,我相信是这样的:
console.log(`경주마 이름 : ${no1} \n 통산 승률: ${no2}, 통산 복승률: ${no3}, 최근 1년 승률: ${no4} \n 최근경주거리: ${no5}, 통산착순상금: ${no6}, 최근1년착순상금: ${no7}, 최근6개월수득상금: ${no8}`);
然后只需添加一个document.write()
调用:
document.write(`경주마 이름 : ${no1} \n 통산 승률: ${no2}, 통산 복승률: ${no3}, 최근 1년 승률: ${no4} \n 최근경주거리: ${no5}, 통산착순상금: ${no6}, 최근1년착순상금: ${no7}, 최근6개월수득상금: ${no8}`);
这会将页面上的当前文本替换为您正在输入的项目console.log()
。
推荐阅读
- c++ - 在从左值引用类型推导出的类型上调用静态 constexpr 成员函数时,clang 和 gcc 不一致
- reactjs - 无法更改 Formik 表单文本字段
- mysql - 如何在大 mysql 表中找到时间数据的间隙
- mysql - 在 Windows 终端中读取 laravel .env 值并将它们用作批处理文件中 mysql 的凭据
- c# - 在 Unity 中使用 OverlapSphere 对敌人造成伤害
- android - Expo FCM 推送通知声音不起作用
- ios - 如何在资产目录中设置可访问性标签?Xcode 11
- python - 当在 kafka 队列中超过一个晚上没有进行任何条目时,Python 使用者脚本在服务器上退出
- ios - branch.io swift中的共享表选项
- rxjs - Angular 8 Subject 不会在事件上触发