Get the App
SLTechnology News&Howtos  ›  Development  › 

Steps to solve garbled code in remote page crawling

Shulou Source: shulou.com Published: 2022-06-03 08:36:51 11月15日 Update

This article introduces the relevant knowledge of "solving the methods and steps of garbled in remote page crawling". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Ff provides the overrideMimeType method, which can specify the encoding of the return value, so it is relatively simple to solve, as long as you point this method to gb2312. For IE, you can use vbs cooperation to transcode, and gb2utf8 to convert the received binary data, in which the execScript method is used to call the function of vbs.

The code is as follows:

LoadPage ("index.htm")

Function loadPage (url) {

Var xh=window.Event?new XMLHttpRequest (): new ActiveXObject ("Microsoft.XMLHTTP")

Xh.open ("GET", url,true)

If (window.Event)

Xh.overrideMimeType ("text/xml;charset=gb2312")

Xh.onreadystatechange=function () {

If (xh.readyStatekeeper 4)

Return

Var v

V=window.Event?xh.responseText:window.gb2utf8 (xh.responseBody)

Alert (v)

}

Window.gb2utf8=function (data) {

Var glbEncode= [], t,i,j,len

Gb2utf8_data=data

ExecScript ("gb2utf8_data = MidB (gb2utf8_data, 1) +'", "vbscript")

T=escape (gb2utf8_data) .replace (/% ucharg, "). Replace (/ (. {2}) (. {2}) / g,"% $2% replace 1 "). Replace (/% ([Amurz].)% (. {2}) / g," @ $1 $2 ")

T=t.split ("@")

ITunes 0

Len=t.length

While (+ + I

Tags: Methods garbled steps pages content more knowledge coding practicality learning and then binary code functions dilemmas actual situation pointing data articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple Huawei MariaDB Microsoft