|
-
Mar 24th, 2005, 09:26 PM
#1
Thread Starter
New Member
[Resolved]How to get a part of a web?
I want to get a weather report from one website. how can I do it?
I use a "Microsoft Web Exploror ", but get the whole web page.
how can I do ?
Last edited by ustb_lichking; Mar 25th, 2005 at 12:36 PM.
Reason: :) no reason
-
Mar 24th, 2005, 10:32 PM
#2
Re: How to get a part of a web?
Parse through the HTML and extract that portion. You might want to create a web service for this in fact.
-
Mar 25th, 2005, 08:36 AM
#3
Hyperactive Member
Re: How to get a part of a web?
Here is some sample code that may help you get started.
VB Code:
<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Net" %>
<script runat="server">
Sub Page_Load(s as Object, e as Eventargs)
Dim strmReader as StreamReader = Nothing
Dim StrURL as String = "http://www.vbforums.com/index.php?"
Dim objRequest as WebRequest = WebRequest.Create(strUrl)
Dim objResponse as WebResponse = objRequest.GetResponse()
strmReader = New StreamReader(objResponse.GetResponseStream())
Dim strContent as String = strmreader.ReadToEnd()
Dim RegEx as Regex = _
New Regex("<!-- NEWS -->((.|\n)*?)<!-- End of NEWS -->", _
RegexOptions.IgnoreCase)
Dim getMatch as Match = RegEx.Match(strContent)
lblbody.Text = (getMatch.Value)
End Sub
</script>
<html>
<head>
<title>Screen Scrape Demo</title>
</head>
<body>
<p>
<asp:Label id="lblBody" runat="server"></asp:Label>
</p>
</body>
</html>
In this sample I am just parsing out the news section of the VB Forums page using regular expressions. I adapted this code from a sample I found on the Internet so I can't help you much with the regular expression part. However, if there is something inside the html the identifies the section you want to scrape this code should work for you. If you look at the source of the VB Forums page you will see the news tags I have in the New Regex Section.
Here you can see this sample code in action. Basicaly you just need to put lblBody in the part of your page that you want the scrape to appear. Keep in mind there may be some legal issues when you scrape content from a site so you should probably get permission before doing so.
-
Mar 25th, 2005, 12:34 PM
#4
Thread Starter
New Member
Re: How to get a part of a web?
Thank you for all your help.
I only want to know weather report by using my program.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|