1

I am new to decoding hence I am unable to decode below response while using UrlFetchApp.

Below is the function I am using to fetch data but getting values in unicode which I need to decode. Any function that I can use to decode this?

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);
  
}
Athar K
  • 191
  • 3
  • 18
  • Can you add any details like error problem encountered? [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask), [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) Show the community what you have tried. – abielita Nov 21 '18 at 07:05

2 Answers2

1

Although I'm not sure whether this is the best way, how about this modification?

Modified script:

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)
}

Result:

When above modified script is used, as a sample, the values are converted as follows.

From:
\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
To:
<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

References:

If I misunderstand your question, I'm sorry.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
0
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)
}