Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Steps to solve garbled code in remote page crawling

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report