In doing collection of friends will know that often come across the content is garbled, below we will look at an ASP tutorial to collect data and automatically judge the page encoding and conversion bar.
<% @LANGUAGE = "JAVASCRIPT" codepage= "65001"%>
<meta http-equiv= " Content-type "content=" text/html; Charset=utf-8 ">
<title>asp automatically determines page encoding and conversion </title>
<%server.scripttimeout= 9999999;
function send_request (URL) {
var codedtext;
Http_request = Server.CreateObject ("Microsoft.XMLHTTP");
Http_request. Open ("Get", url,false);
Http_request. Send (NULL);
if (http_request. ReadyState = = 4) {
//Automatic decision encoding start
var charresult = http_request. Responsetext.match (/charset= (s+) ">/i");
if (charresult!= null) {
var Cset = charresult[1];
}else{cset = "gb2312"}//use gb2312 encoding for Web sites that are not available, and can automatically change
//automatic judgment encoding end
Codedtext = Bytestobstr (http_request. Responsebody,cset);
}else{
Codedtext = "Erro";
}
Return (Codedtext);
}
Function Bytestobstr (body,cset) {
var objstream;
objstream = Server.CreateObject ("ADODB.stream");
Objstream. Type = 1;
objstream. Mode = 3;
Objstream. Open ();
Objstream. Write (body);
Objstream. Position = 0;
Objstream. Type = 2;
Objstream. Charset = Cset;
Bytestobstr = objstream. Readtext;
Objstream. Close;
return (BYTESTOBSTR);
}%>
<body>
<%response.write (send_request ("http://www.3lian.com/404.htm"))%>
</ Body>