Google App Script UrlFetch not giving HTML output but JavaScript ouput

六月ゝ 毕业季﹏ 提交于 2019-12-14 03:15:33

问题


I am trying to fetch content from following web page

http://www.mfinante.ro/infocodfiscal.html?cod=10376836

My code is

var fetchString="www.mfinante.ro/infocodfiscal.html?cod=10376836";
var response = UrlFetchApp.fetch(fetchString);

When I view page source of above link it shows correct content but urlfetch showing different content.

In other words view source of above page shows html but urlfetch shows only javascript.

view-source:http://www.mfinante.ro/infocodfiscal.html?cod=10376836

view source behaving differently sometime shows html sometimes javascript.


回答1:


Use PhantomJS and the following js code:

var system = require('system');
var page = require('webpage').create();

page.open(system.args[1], function(status) {
        setTimeout(function(){
                console.log(page.plainText);
                phantom.exit();
        }, 10000);
});

In linux:

phantomjs visit.js http://www.mfinante.ro/infocodfiscal.html?cod=5066472

In Windows:

phantomjs.exe visit.js http://www.mfinante.ro/infocodfiscal.html?cod=5066472


来源:https://stackoverflow.com/questions/31452272/google-app-script-urlfetch-not-giving-html-output-but-javascript-ouput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!