[英]NodeJS Request, Wait for java-script injected content
i am trying to get a entire page contents. 我正在尝试获取整个页面的内容。 The issue im having is that on the particular page is the following code:
我所遇到的问题是,在特定页面上的代码如下:
<div class="line-item" data-get-url="/currency/line-items/378303049"
style="display: none;">
This content appears to be javascript injected, How do i make request wait for the content to be injected? 该内容似乎是JavaScript注入的,我如何发出请求以等待内容被注入?
Thank you to anyone that can help me with this. 谢谢任何能帮助我的人。
Current code: 当前代码:
var url = 'https://www.daniel.com/my/groupadmin.aspx?gid=' + groupId +
'#nav-revenue';
var headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3712.0 Safari/537.36',
'Cookie': cookieString,
'Referer': 'https://www.daniel.com/groups/' + groupId
};
request.post({ url: url, headers: headers, followAllRedirects: true }, function (e, r, body) {
var mystr = body;
//console.log(body);
//Splitting it with : as the separator
var myarr = mystr.split('<div class="summary" data-get-url="/currency/summary/');
var myvar = myarr[1];
var token = myvar.split('">');
var tokenbody = token[0];
console.log(mystr);
console.log(tokenbody); // "nu"
});
With about 4 headaches, 5 energy drinks, 1 cup of coffee and a broken monitor i have finally managed to resolve my problem. 终于有了约4头疼,5杯能量饮料,1杯咖啡和一台破裂的显示器,我终于设法解决了我的问题。 I have swapped from using request and im now using unirest.
我已经从使用请求和即时消息交换使用了unirest。 With unirest i can make the first request to the site, then a second while keeping logged in and the headers set.
使用unirest,我可以向站点发出第一个请求,然后在保持登录状态和设置标题的情况下发出第二个请求。 Thanks to anyone who helped and responded.
感谢任何帮助和回应的人。 Goodluck to anyone else that needs to do this!
向其他需要这样做的人表示好运! I wish you all the very best!
祝您一切顺利!
我换成了使用unirest,所以我可以保持连接,然后再重定向到我需要的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.