2016-09-25 38 views
0

我有一个流星web应用程序。 (例如http://www.merafi.com)。我想使用Google Apps脚本来抓取网站。我为此写了一个小脚本。我如何刮流星webapp?

function myFunction() { 
    const url = 'http://www.merafi.com'; 
    const response = UrlFetchApp.fetch(url, {muteHttpExceptions: true}); 
    return response.getContentText(); 
} 

该脚本在Google Spreadsheet中用作宏。

=myFunction() 

刮流星webapp的问题是,我得到一个空的身体,其中只有脚本标记。如何获取body标签内的内容?

enter image description here

+1

您需要一些运行JS的抓取工具,例如phantomJS,nightmarejs或Selenium – Rentrop

+0

不幸的是,我在Google Apps脚本中没有该工具。 https://developers.google.com/apps-script/reference/url-fetch/ – vijayst

+0

好吧,那么要么你不得不使用Google Apps脚本以外的东西,否则你有很多工作需要重新编写。 – CodeChimp

回答

0

有些像爬虫或PhantomJS是NightmareJS所需的页面加载后运行流星JS。不幸的是,Google Apps脚本环境不允许加载外部依赖/软件包。 Apps脚本API没有任何方法在单独的iframe/webview中加载页面。这不可能使用Google Apps脚本。

感谢@Floo和@CodeChimp回答评论中的问题。