XMLHttp ASP remote access to Web page content Code _ Thieves/Collection

Source: Internet
Author: User
Tags function definition

Copy Code code 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 ' determines if the document has been parsed to make the client accept the return message
Exit function
End If
Gethttppage=bbytestobstr (objxml.responsebody) ' returns information, with function definition encoding
Set Objxml=nothing ' Off
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 directly using the XMLHTTP to invoke the page with Chinese characters will be garbled
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 directly using the XMLHTTP to invoke the page with Chinese characters will be garbled
Bytestobstr = objstream. ReadText
Objstream. Close
Set objstream = Nothing
End Function

Related Article

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.