我是解码新手,因此在使用UrlFetchApp时无法解码以下响应。
下面是我用来获取数据的函数,但我需要解码unicode中的值。有什么函数可以用来解码吗?
function scrape() {
var url = UrlFetchApp.fetch("https://immi.homeaffairs.gov.au/visas/working-in-australia/skillselect/invitation-rounds");
var elements =/id="ctl00_PlaceHolderMain_PageSchemaHiddenField_Input" (.*?)/>/gim;
var x = url.getContentText().match(elements);
Logger.log(x);
}
虽然我不确定这是否是最好的方法,但这次修改怎么样?
修改的脚本:
function scrape() {
var url = UrlFetchApp.fetch("https://immi.homeaffairs.gov.au/visas/working-in-australia/skillselect/invitation-rounds");
var elements =/id="ctl00_PlaceHolderMain_PageSchemaHiddenField_Input" (.*?)/>/gim;
var x = url.getContentText().match(elements);
var res = unescape(x[0].replace(/\u/g, "%u")); // Added
Logger.log(res)
}
结果:
当使用上述修改后的脚本时,作为示例,值转换如下。
发件人:u003cpu003eThe table below shows the number of invitations issued in the SkillSelect invitation round on 11 September 2018.u003c/pu003ennu003ch3u003eInvitations issued on 11 September 2018u003c/h3u003enn
收件人:<p>The table below shows the number of invitations issued in the SkillSelect invitation round on 11 September 2018.</p>nn<h3>Invitations issued on 11 September 2018</h3>nn
参考文献:
- unescape((
- replace((
如果我误解了你的问题,我很抱歉。
function scrape() {
var url = UrlFetchApp.fetch("https://immi.homeaffairs.gov.au/visas/working-in-australia/skillselect/invitation-rounds");
var elements =/id="ctl00_PlaceHolderMain_PageSchemaHiddenField_Input" (.*?)/>/gim;
var x = url.getContentText().match(elements);
var res = unescape(x[0].replace(/\u/g, "%u")); // Added
Logger.log(res)
}