Google App Script UrlFetch不提供HTML输出,而是输出JavaScript [英] Google App Script UrlFetch not giving HTML output but JavaScript ouput

查看:199
本文介绍了Google App Script UrlFetch不提供HTML输出,而是输出JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从以下网页提取内容

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



我的代码是

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

当我查看上面链接的页面源代码时,它显示正确的内容,但是显示不同内容的urlfetch。



换句话说,上述页面的查看源显示html,但urlfetch只显示javascript。



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



查看源代码有时会显示html,有时会显示html。

解决方案

使用PhantomJS和以下js代码:

  var system = require('system'); 
var page = require('webpage')。create();
$ b page.open(system.args [1],function(status){
setTimeout(function(){
console.log(page.plainText);
phantom.exit();
},10000);
});

在linux中:

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

在Windows中:

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


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.

解决方案

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

这篇关于Google App Script UrlFetch不提供HTML输出,而是输出JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆