1 Public Function GetBody(ByVal URL$, Optional ByVal Coding$ = "GB2312") 2 Dim ObjXML 3 On Error Resume Next 4 Set ObjXML = CreateObject("Microsoft.XMLHTTP") 5 With ObjXML 6 .Open "Get", URL, False, "", "" 7 .setRequestHeader "If-Modified-Since", "0" 8 .Send 9 GetBody = .responseBody 10 End With11 GetBody = BytesToBstr(GetBody, Coding) 12 Set ObjXML = Nothing13 End Function14 15 Public Function BytesToBstr(strBody, CodeBase) 16 Dim ObjStream 17 Set ObjStream = CreateObject("Adodb.Stream") 18 With ObjStream 19 .Type = 120 .Mode = 321 .Open 22 .Write strBody 23 .Position = 024 .Type = 225 .Charset = CodeBase 26 BytesToBstr = .ReadText 27 .Close 28 End With29 Set ObjStream = Nothing30 End Function31 '注意第一行代码中Coding$ = "GB2312" 表示获取的网页内容为GB2312编码格式,如果出现乱码,那么就换成Coding$ = "utf-8"32 '返回值为: 33 a = GetBody("http://www.baidu.com")
本文转自: