如何通过休息请求进入html源代码

时间:2017-09-07 08:59:42

标签: javascript jquery html rest fetch

我希望通过REST请求获取HTML源数据来渲染另一个网站的某些值,将span标记内的值控制到我的控制台日志并将其呈现给我的HTML。

我无法通过我当前的代码来解决这个问题,他在DOM准备好之前收到了数据,而我还不需要特定的san标签。

我当前的代码 -

async function uiTagChecking() {

        let url ='http://production.com:8000/loginPage#';

        fetch(url)
            .then(await sleep(6000))
            .then(response => response.text())
            .then(pageSource => console.log(pageSource));
}

我提取的当前源代码(这是在DOM准备好之前,还没有所需的span标记)

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>loading...</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link rel="icon"
        type="image/png"
        href="images/favicon.png?v=9">
  <!--<link href="assets/vendors/keylines/map/leaflet.css" rel="stylesheet">-->

<link href="XXXX" rel="stylesheet"></head>
<body>
<div id="app"></div>
<script src="assets/vendors/jquery.min.js"></script>
<script type="text/javascript" src="XXXX/index-c08574aac712ae81e016.js"></script></body>
</html>

我想打印和渲染的span标记 -

<span class="version-for-qa">2.1.1</span>

但只有在重定向结束且DOM准备就绪后才会出现。

技术信息

节点JS

的JavaScript

HTML + CSS

我的服务器文件(快递):

var express = require('express');
var cors = require('cors');
var app = express();
var path = require("path");
var fetch = require('fetch-cookie')(require('node-fetch'));
var btoa = require('btoa');
var http = require('http');
var fs = require('fs');


var corsOptionsDelegate = function (req, callback) {
    var corsOptions;
    if (whitelist.indexOf(req.header('Origin')) !== -1) {
        corsOptions = { origin: true } // reflect (enable) the requested origin in the CORS response
    }else{
        corsOptions = { origin: false } // disable CORS for this request
    }
    callback(null, data , corsOptions) // callback expects two parameters: error and options
};

app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/view');
app.set('view engine', 'html');


app.use(express.static(path.join(__dirname, 'public')));

app.get('/', function(req, res){
    res.render('index');
    res.render('logo');
    res.writeHead(200, {'Content-Type': 'application/json'});
});

app.use(cors());

app.set(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

app.get('/products/:id', function (req, res, next) {
    res.json({msg: 'This is CORS-enabled for all origins!'})
});


app.listen(8033, function () {
    console.log('CORS-enabled web server listening on port 8033')
});

0 个答案:

没有答案