ASP uses XMLHTTP to crawl Web content

Source: Internet
Author: User
Tags date end
xml| Web page

XMLHTTP Crawl Web page, recently in the blog to see this article, so on the way posted to the blog,
Original url:http://www.cnblogs.com/hover/archive/2004/10/09/36212.aspx (Blog Park-flying. Net blog)

Crawl Web pages. I want to implement thorough update weather forecast. The XMLHTTP component is used to crawl the specified portion of the page.
Need to split HTML source code
In this example, the crawled HTML source code is as follows
<p align=left>2004 Year August 24 Tuesday; Daytime: Sunny Sometimes cloudy southerly 3-4 class; Night: Clear South wind 3-4; temperature: Up to 29 ℃ minimum 19℃</p>
And the program is from
Search by August 24, 2004 for keywords until the </p> knot speed
The contents of the capture became "August 24, 2004 Tuesday; Day: Sunny sometimes cloudy southerly 3-4 class; Night: Clear South wind 3-4; temperature: Max 29 ℃ minimum 19 ℃"
It's clean. Record it.

<%
On Error Resume Next
server.scripttimeout=9999999
Function Gethttppage (Path)
t = GetBody (Path)
Gethttppage=bytestobstr (T, "GB2312")
End Function

Function getbody (URL)
On Error Resume Next
Set retrieval = CreateObject ("Microsoft.XMLHTTP")
With retrieval
. Open "Get", url, False, "", ""
. Send
GetBody =. Responsebody
End With
Set retrieval = Nothing
End Function

Function Bytestobstr (Body,cset)
Dim objstream
Set objstream = Server.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
Function newstring (WSTR,STRNG)
Newstring=instr (LCase (WSTR), LCase (STRNG))
If Newstring<=0 then Newstring=len (WSTR)
End Function
%>

<body bgcolor= #ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<!--start-->

<%
Dim Wstr,str,url,start,over,dtime
Dtime=year (date) & "Year" &month (date) & "Month" &day (date) & "Day"
Url= "http://www.qianhuaweb.com/"
Wstr=gethttppage (URL)
Start=newstring (Wstr,dtime)
Over=newstring (WSTR, "</p>")
Body=mid (Wstr,start,over-start)

Response.Write "<marquee onmouseover=this.stop (); Onmouseout=this.start ();> "&body&" </marquee> "


%>
<!--end-->
</body>




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.