Decode/Unescape Unicode Google 应用程序脚本
Decode/Unescape Unicode Google App Scripts
我是解码新手,因此在使用 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)
}
结果:
使用上述修改后的脚本时,作为示例,值转换如下。
从:
\u003cp\u003eThe table below shows the number of invitations issued in the SkillSelect invitation round on 11 September 2018.\u003c/p\u003e\n\n\u003ch3\u003eInvitations issued on 11 September 2018\u003c/h3\u003e\n\n
到:
<p>The table below shows the number of invitations issued in the SkillSelect invitation round on 11 September 2018.</p>\n\n<h3>Invitations issued on 11 September 2018</h3>\n\n
参考文献:
如果我误解了你的问题,我很抱歉。
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)
}
我是解码新手,因此在使用 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)
}
结果:
使用上述修改后的脚本时,作为示例,值转换如下。
从:\u003cp\u003eThe table below shows the number of invitations issued in the SkillSelect invitation round on 11 September 2018.\u003c/p\u003e\n\n\u003ch3\u003eInvitations issued on 11 September 2018\u003c/h3\u003e\n\n
到:
<p>The table below shows the number of invitations issued in the SkillSelect invitation round on 11 September 2018.</p>\n\n<h3>Invitations issued on 11 September 2018</h3>\n\n
参考文献:
如果我误解了你的问题,我很抱歉。
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)
}