Results 1 to 4 of 4

Thread: [Resolved]How to get a part of a web?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    5

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: How to get a part of a web?

    Here is some sample code that may help you get started.
    VB Code:
    1. <%@ Page Language="VB" %>
    2. <%@ import Namespace="System.IO" %>
    3. <%@ import Namespace="System.Net" %>
    4. <script runat="server">
    5.     Sub Page_Load(s as Object, e as Eventargs)
    6.             Dim strmReader as StreamReader = Nothing
    7.  
    8.         Dim StrURL as String = "http://www.vbforums.com/index.php?"
    9.  
    10.         Dim objRequest as WebRequest = WebRequest.Create(strUrl)
    11.         Dim objResponse as WebResponse = objRequest.GetResponse()
    12.  
    13.         strmReader = New StreamReader(objResponse.GetResponseStream())
    14.  
    15.         Dim strContent as String = strmreader.ReadToEnd()
    16.         Dim RegEx as Regex = _
    17.             New Regex("<!-- NEWS -->((.|\n)*?)<!-- End of NEWS -->", _
    18.                 RegexOptions.IgnoreCase)
    19.         Dim getMatch as Match = RegEx.Match(strContent)
    20.         lblbody.Text = (getMatch.Value)
    21.     End Sub
    22.  
    23. </script>
    24. <html>
    25. <head>
    26.     <title>Screen Scrape Demo</title>
    27. </head>
    28. <body>
    29.  
    30.     <p>
    31.         <asp:Label id="lblBody" runat="server"></asp:Label>
    32.     </p>
    33.  
    34. </body>
    35. </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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width