nubbbbbbb-_-bb nubbbbbbb-_-bb - 7 months ago 18
Javascript Question

diamond character(�) appeared after fetch url in google script

newbb got a question about character problem between google and webpage table.

I'm using google sheet and script to get a table from a opened website to google spreadsheet.

the page url is below (um.. I have reputation limit)

http://www.g2b.go.kr:8101/ep/tbid/integrationWbidderList.do?searchType=1&bidSearchType=3&taskClCds=3&bidNm=&searchDtType=2&fromBidDt=&toBidDt=&fromOpenBidDt=2012%2F01%2F01&toOpenBidDt=2012%2F02%2F01&setMonth2=6&radOrgan=1&instNm=&instSearchRangeType=&refNo=&area=00&areaNm=&industry=&industryCd=&budget=&budgetCompare=UP&detailPrdnmNo=&detailPrdnm=&procmntReqNo=&intbidYn=&regYn=Y&recordCountPerPage=30


At first time I used google spreadsheet function 'importhtml'.

The tables works fine but the language is changed weird.
I've changed google language option but didn't work.

picture of character problem at google sheet

so I trying to get HTML of table in google script by following api fetch example and

I thought this problem comes from charset.. encoding.. or something

so added an option about charset ('euc-kr' from the page HTML source)

//in google apps script
function myFunction() {
var option =
{
"contentType" : "charset=euc-kr"
};
var response = UrlFetchApp.fetch("~~~url~~~", option);
Logger.log(response.getContentText());
}


And It success to take HTML as text

but the language(same above language) looks like this..

diamond characters

How can I solve this problem..? I need normal text table or HTML text in google sheet or script. without MS excel.

Answer

According to the docs you can pass a charset to getContentText:

response.getContentText('EUC-KR')

This should return the characters correctly.

https://developers.google.com/apps-script/reference/url-fetch/http-response#getcontenttextcharset

Comments