【发布时间】:2019-02-07 13:02:14
【问题描述】:
我想通过 nodejs 获取一些 html 并在我的浏览器中获取输出,所以我使用了以下代码
const express = require('express')
const app = express()
const fetch = require("node-fetch");
const port = 3000
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
fetch("https://example.com/results.php") .then(res => res.text())
.then(data => obj = data)
.then(() =>
app.get('/', (req, res) => res.send(obj))
)
然后我使用node app启动应用程序
现在当我运行 localhost:3000 时,每次都会给出相同的输出,但 https://example.com/results.php 是动态结果页面,每次重新加载时都会返回各种结果。
所以我需要的是每次打开 localhost:3000 时,它必须再次获取 url 并在浏览器窗口中返回新结果,对不起,我对 nodejs 完全陌生,我只是想从 nodejs 重新制作 php curl。
【问题讨论】:
标签: javascript node.js