上一篇的我找到的转换代码不太理想。任然有一些是“?”乱码,经过向多方学习最后找到两个方法。
第一种方法
设置一个按钮,一个文本框。文本框的Multiline属性设置为true
- Const URLaddr = "http://api.douban.com/book/subject/isbn/9787115157676" '豆瓣网获取书籍信息网页地址
- DimIEreadAsObject
- Dimi&,jj&,aa$
- PrivateSubCommand1_Click()
- SetIEread=CreateObject("WinHttp.WinHttpRequest.5.1")
- CallByNameIEread,"Open",VbMethod,"GET",URLaddr,True
- CallByNameIEread,"Send",VbMethod
- CallByNameIEread,"WaitForResponse",VbMethod
- aa=CallByName(IEread,"ResponseText",VbMethod)
- Text1.Text=aa
- EndSub
第二种方法
需要引用Microsoft XML,v2.6
- FunctionGetBody(urls as string,Charset as string)
- GetBody=""
- OnErrorResumeNext
- DimAdo_StreamAsADODB.Stream
- DimObj_XMLHTTPAsMSXML2.XMLHTTP
- SetObj_XMLHTTP=NewMSXML2.XMLHTTP
- SetAdo_Stream=NewADODB.Stream
- Obj_XMLHTTP.Open"get",urls,False
- Obj_XMLHTTP.send
- IfObj_XMLHTTP.readyState=4Then
- IfCharset=""Then
- GetBody=Obj_XMLHTTP.responseBody
- Else
- Ado_Stream.Type=1
- Ado_Stream.Mode=3
- Ado_Stream.Open
- Ado_Stream.WriteObj_XMLHTTP.responseBody
- Ado_Stream.Position=0
- Ado_Stream.Type=2
- Ado_Stream.Charset=Charset
- GetBody=Ado_Stream.ReadText
- Ado_Stream.Close
- EndIf
- EndIf
- SetAdo_Stream=Nothing
- SetObj_XMLHTTP=Nothing
- EndFunction
- PrivateSubCommand1_Click()
- DimTxmlAsString
- Txml=GetBody("http://api.douban.com/book/subject/isbn/9787115157676","UTF-8")
- Debug.PrintTxml
- EndSub