Xmlhttp asp Remote Access To webpage content code

Source: Internet
Author: User

CopyCode The Code is as follows: url = "http://www.csdn.net /"
Wstr = gethttppage (URL)
Start = newstring (wstr, "Resource Selection <! -- Download --> ")
Over = newstring (wstr, "<Div class =" "friendlink" "> ")
Body = mid (wstr, 200,500)

Response. Write body

Function gethttppage (URL)
Dim objxml
Set objxml = Createobject ("msxml2.xmlhttp") 'Definition
Objxml. Open "get", URL, false' open
Objxml. Send () 'send
If objxml. readystate <> 4 then' is used to determine whether the document has been parsed to receive the returned message from the client.
Exit Function
End if
Gethttppage = bbytestobstr (objxml. responsebody) 'returns information and uses function-defined encoding.
Set objxml = nothing 'disabled
If err. Number <> 0 then err. Clear
End Function

Function newstring (wstr, strng)
Newstring = instr (lcase (wstr), lcase (strng ))
If newstring <= 0 then newstring = Len (wstr)
End Function

Function bbytestobstr (Body)
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 = "gb2312"
'Convert the original default UTF-8 encoding to gb2312 encoding, otherwise the web page with Chinese characters will be garbled directly by calling XMLHTTP
Bbytestobstr = objstream. readtext
Objstream. Close
Set objstream = nothing
End Function

function bytestobstr (body)
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 = "UTF-8"
'convert the original default UTF-8 encoding to gb2312 encoding, otherwise, the webpage with Chinese characters will be garbled by calling XMLHTTP directly
bytestobstr = objstream. readtext
objstream. close
set objstream = nothing
end function

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.