VBS or ASP when collecting Articles page coding problem _ Thieves/collection
Source: Internet
Author: User
'/*=========================================================================
' * Intro Research Web page coding for a long time, because recently to design a link detection of the VBS script, and the person you link to the page is likely to be a variety of encodings, the previous approach is: if you use GB2312 to find out and then use UTF-8 Check, Can not find proof that the other party did not give you a link although not 100% correct, but also almost, the two kinds of coding with a lot of people, accidentally in a favorite folder in an address to see a thought, and finally in the collection of articles automatically judge the code of the page. Because the research process of this problem for a long time, although now feel simple, presumably many people are still looking for, so put these three functions posted out.
' * FileName getwebcodepage.vbs
' * Author yongfa365
' * Version v2.0
' * WEB http://www.yongfa365.com
' * Email yongfa365[at]qq.com
' * Firstwrite http://www.yongfa365.com/Item/GetWebCodePage.vbs.html
' * Madetime 2008-01-29 20:55:46
' * lastmodify 2008-01-30 20:55:46
' *==========================================================================*/
' Get the matching content, return the array
' Getcontents (expression, string, return reference value)
' MsgBox getcontents ("a" (. +?) B "," a23234b ab a67896896b sadfasdfb ", True) (0)
Function getcontents (patrn, strng, Yinyong)
' By www.yongfa365.com reprint please keep the link so that the end users get the latest update information in time
On Error Resume Next
Set re = New RegExp
Re. Pattern = Patrn
Re. IgnoreCase = True
Re. Global = True
Set matches = Re. Execute (STRNG)
If Yinyong Then
For i = 0 to Matches.count-1
If matches (i). Value<> "" "Then Retstr = retstr & Matches (i). Submatches (0) & "Liu Yong FA"
Next
Else
For each omatch in matches
If omatch.value<> "" Then retstr = retstr & Omatch.value & "Liu Yong FA"
Next
End If
getcontents = Split (Retstr, "Liu Yong FA")
End Function
Function gethttppage (URL)
On Error Resume Next
Set xmlhttp = CreateObject ("MSXML2. XMLHTTP ")
xmlHTTP. Open ' get ', url, False
xmlHTTP. Send
If XMLHTTP. status<>200 Then Exit Function
GetBody = xmlhttp. Responsebody
' Liu YONGFA (www.yongfa365.com) In this idea is, first based on the return of the string to find, find the file head, if not yet used GB2312, generally can directly match the encoding.
' In the returned string, although the Chinese is garbled, it does not affect the encoding we take,
Getcodepage = getcontents ("charset=[" "']*" ([^ ", ']+ ')", XMLHTTP. ResponseText, True) (0)
' Look at the code in the header file.
If Len (getcodepage) <3 Then getcodepage = getcontents ("charset=[" "']*" ([^ ", ']+ ')", Xmlhttp.getresponseheader (" Content-type "), True) (0)
If Len (getcodepage) <3 Then getcodepage = "gb2312"
Set xmlhttp = Nothing
' This sentence should be shielded from the official use.
WScript.Echo URL & "-->" & Getcodepage
Gethttppage = Bytestobstr (GetBody, Getcodepage)
End Function
Function bytestobstr (body, Cset)
On Error Resume Next
Dim objstream
Set objstream = 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
Set objstream = Nothing
End Function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service