我想爲本頁上的每個鏈接追查頁面後面的詳細信息頁面。從網站刮臉,用javascript:subOpen href鏈接
我能得到這個網頁上的所有信息:PAGE
不過,我想獲得的所有信息的詳細信息頁面上,但在href鏈接看起來像,例如:
href="javascript:subOpen('9ca8ed0fae15d43dc1257e7300345b99')"
以下是使用ImportHTML
函數獲得總體概述的示例電子表格。
任何建議如何獲得詳細信息頁面?
UPDATE
我採取了以下方法:
function doGet(e){
var base = 'http://www.ediktsdatei.justiz.gv.at/edikte/ex/exedi3.nsf/'
var feed = UrlFetchApp.fetch(base + 'suche?OpenForm&subf=e&query=%28%5BVKat%5D%3DEH%20%7C%20%5BVKat%5D%3DZH%20%7C%20%5BVKat%5D%3DMH%20%7C%20%5BVKat%5D%3DMW%20%7C%20%5BVKat%5D%3DMSH%20%7C%20%5BVKat%5D%3DGGH%20%7C%20%5BVKat%5D%3DRH%20%7C%20%5BVKat%5D%3DHAN%20%7C%20%5BVKat%5D%3DWE%20%7C%20%5BVKat%5D%3DEW%20%7C%20%5BVKat%5D%3DMAI%20%7C%20%5BVKat%5D%3DDTW%20%7C%20%5BVKat%5D%3DDGW%20%7C%20%5BVKat%5D%3DGA%20%7C%20%5BVKat%5D%3DGW%20%7C%20%5BVKat%5D%3DUL%20%7C%20%5BVKat%5D%3DBBL%20%7C%20%5BVKat%5D%3DLF%20%7C%20%5BVKat%5D%3DGL%20%7C%20%5BVKat%5D%3DSE%20%7C%20%5BVKat%5D%3DSO%29%20AND%20%5BBL%5D%3D0').getContentText();
var d = document.createElement('div'); //assuming you can do this
d.innerHTML = feed;//make the text a dom structure
var arr = d.getElementsByTagName('a') //iterate over the page links
var response = "";
for(var i = 0;i<arr.length;i++){
var atr = arr[i].getAttribute('onclick');
if(atr) atr = atr.match(/subOpen\((.*?)\)/) //if onclick calls subOpen
if(atr && atr.length > 1){ //get the id
var detail = UrlFetchApp.fetch(base + '0/'+atr[1]).getContentText();
response += detail//process the relevant part of the content and append to the reposnse text
}
}
return ContentService.createTextOutput(response);
}
然而,在運行方法時,我得到一個錯誤:
ReferenceError: "document" is not defined. (line 6, file "")
什麼是document
的對象?
我用webapp更新了Google Spreadsheet。
我感謝您的回覆!
[此問題]的副本(http://stackoverflow.com/questions/31452272/google-app-script-urlfetch-not-giving-html-output-but-javascript-ouput)。 – Mogsdad