Results 1 to 10 of 10

Thread: HTTPweb request and show only a little part

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    48

    HTTPweb request and show only a little part

    Hi

    I have this little script that shows a website on my site
    Code:
     <%@ Page Language="VB" Debug="True" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <%@ Import Namespace="System.Text" %>
    <%@ Import Namespace="System.Net" %>
    <%@ Import Namespace="System.IO" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <script runat="server">
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim request As HttpWebRequest = CType(WebRequest.Create("http://www.dmi.dk/dmi/index/danmark/regionaludsigten/ostjylland.htm"), HttpWebRequest)
            Dim response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
            Dim reader As StreamReader =  New StreamReader(response.GetResponseStream(),Encoding.GetEncoding("iso-8859-1"))
            someLabel.Text = reader.ReadToEnd()
        End Sub    
    </script>
    <html>
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="content-language" content="dan" />
    <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:Label ID="someLabel" runat="server"></asp:Label>
        </form>
    </body>
    </html>
    i want only to show the weather cast not all the other things, how can i do that !?

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: HTTPweb request and show only a little part

    Do you mean just the image that is also shown here on its own?

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    48

    Re: HTTPweb request and show only a little part

    Quote Originally Posted by Grimfort View Post
    Do you mean just the image that is also shown here on its own?
    Ok can see the problem/solution on that one.
    Bad ex. see this link then http://vejret.dk/vaer.aspx?ID=11394652&zoomlevel=8

    How can i show only the "City name/Time now/temp"
    i can see that its this part from the site i just need to use....
    Code:
    <div id="divMain2" class="mainDiv">
        
    <table cellspacing="0" cellpadding="0" border="0" style="padding-left:8px;padding-right:8px;background-image:url(elements/sted/header_top_citypage.png);width:914px;height:69px;background-position:center;">
        <tr>
            <td style="width:402px" class="stedText" align="left">
                <span id="PlaceInfo1_lblSted">Billund</span>
            </td>
            <td style="width:340px" class="nowText" align="right" valign="middle">
            <table cellspacing='0px' cellpadding='0px' border='0px'>
    <tr><td class="nowText">kl.&nbsp;17.00</td><td><img src='symbols/s55/4.png' /></td><td  class="nowText">&nbsp;<span  style='color:#0d74b9;font-weight:bold;'>-3&deg;</span>&nbsp;</td><td class='weathercell6'><div style='position:relative;width:40px;height:40px;top:5px;'>
    <div style='position:absolute;top:0px;left:0px;'>
    <img src='symbols/w40/E10.png' /><br/>5 m/s</div>
    </div>
    </td></TR></table>
            </td>
        </tr>
        <tr style="height:1px;background-color:#a0d0f0;"><td colspan='3' style="height:1px;;"></td></tr>
    </table>
        
    <table cellspacing="0" cellpadding="0" border="0" style="width:914px;height:29px">
        <tr>
            <td style="width:8px"></td>
            <td style="width:356px" class="obstext" align="left" valign="middle">
            
            </td>
     
             <td style="width:8px"></td>
     
            <td style="width:550px" class="obstext" align="right" valign="middle" style="border-right: hidden 8px transparent">
            
            <SPAN class='obsdesc'>Sol&nbsp;op:&nbsp;</SPAN>
    <B>07.42</B><SPAN class='obsdesc'>&nbsp;-&nbsp;Sol&nbsp;ned:&nbsp;</SPAN>
    <B>17.33</B>
            </td>
            <td style="width:8px"></td>
        </tr>
    </table>
    </div>
    But how do i do that, the VB.net world is new for me.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: HTTPweb request and show only a little part

    You could extract the part you need with a little bit of fiddling, but it won't work as all the src links will be invalid if inserted into your site. Surely now you are only displaying the text source?

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    48

    Re: HTTPweb request and show only a little part

    Quote Originally Posted by Grimfort View Post
    You could extract the part you need with a little bit of fiddling, but it won't work as all the src links will be invalid if inserted into your site. Surely now you are only displaying the text source?
    That will be ok with only the textsource then i can make my own layout and use some other images, if possible.

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: HTTPweb request and show only a little part

    I have not had to parse html outside a webbrowser control, but a quick search shows there are ways to parse html using mshtml.dll. I will not advocate using this, I'm sure there are far nicer ways but I have not had to do them myself to give advice.

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    48

    Re: HTTPweb request and show only a little part

    Quote Originally Posted by Grimfort View Post
    I have not had to parse html outside a webbrowser control, but a quick search shows there are ways to parse html using mshtml.dll. I will not advocate using this, I'm sure there are far nicer ways but I have not had to do them myself to give advice.
    Cant i use something like this...
    Code:
    <%@ Page Language="VB" Debug="True" ContentType="text/html" ResponseEncoding="iso-8859-1" %> 
    <%@ Import Namespace="System.Text" %> 
    <%@ Import Namespace="System.Net" %> 
    <%@ Import Namespace="System.IO" %> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <script runat="server"> 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
            Dim request As HttpWebRequest = CType(WebRequest.Create("http://vejret.dk/vaer.aspx?ID=11394652&zoomlevel=8"), HttpWebRequest) 
            Dim response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse) 
            Dim reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.GetEncoding("iso-8859-1")) 
       
            Dim input As String = reader.ReadToEnd() 
            Dim StartToken As String = "<div id="divMain2" class="mainDiv">"                                                                                Dim EndToken As String = "</div>"        Dim ContentStartPosition As Integer = Input.IndexOf(StartToken) + StartToken.Length 
            Dim ContentEndPosition As Integer = Input.IndexOf(EndToken) 
            Dim Length As Integer = ContentEndPosition - ContentStartPosition 
            Dim Content As String = Input.Substring(ContentStartPosition, Length) 
            someLabel.Text = Content 
        End Sub 
    </script> 
    <html> 
    <head runat="server"> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <meta http-equiv="content-language" content="dan" /> 
    <title>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
            <asp:Label ID="someLabel" runat="server"></asp:Label> 
        </form> 
    </body> 
    </html>
    or !?

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: HTTPweb request and show only a little part

    You have <\div> ends for other tags which you can not easily tell which is the one you want, unless you start counting begin and ends, which is what a parser does for you. A simple start and end counting could work.

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2011
    Posts
    48

    Re: HTTPweb request and show only a little part

    Quote Originally Posted by Grimfort View Post
    You have <\div> ends for other tags which you can not easily tell which is the one you want, unless you start counting begin and ends, which is what a parser does for you. A simple start and end counting could work.
    Ok, im new to this can u maybe help me or show me and Ex. using start and end counting !?

  10. #10
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: HTTPweb request and show only a little part

    You already have the knowledge, just not how to use it . You find the start as you already have done. Then using the IndexOf, look for the next <div and the next </div

    If <div is found first then add 1 to your counter, if </div is found first then -1 from your counter. Just keep searching forward from the last index when you found a tag. When you have a counter of 0 and you have just found an end tag, thats the end of the whole div.

    Give it a go.

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