2016-09-25 64 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回答評論中的問題。