-
Feb 18th, 2011, 09:59 AM
#1
Thread Starter
Member
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 !?
-
Feb 18th, 2011, 10:17 AM
#2
Re: HTTPweb request and show only a little part
Do you mean just the image that is also shown here on its own?
-
Feb 18th, 2011, 11:24 AM
#3
Thread Starter
Member
Re: HTTPweb request and show only a little part
Originally Posted by Grimfort
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. 17.00</td><td><img src='symbols/s55/4.png' /></td><td class="nowText"> <span style='color:#0d74b9;font-weight:bold;'>-3°</span> </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 op: </SPAN>
<B>07.42</B><SPAN class='obsdesc'> - Sol ned: </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.
-
Feb 18th, 2011, 11:31 AM
#4
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?
-
Feb 18th, 2011, 11:44 AM
#5
Thread Starter
Member
Re: HTTPweb request and show only a little part
Originally Posted by Grimfort
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.
-
Feb 18th, 2011, 12:12 PM
#6
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.
-
Feb 18th, 2011, 01:11 PM
#7
Thread Starter
Member
Re: HTTPweb request and show only a little part
Originally Posted by Grimfort
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 !?
-
Feb 18th, 2011, 01:34 PM
#8
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.
-
Feb 18th, 2011, 03:35 PM
#9
Thread Starter
Member
Re: HTTPweb request and show only a little part
Originally Posted by Grimfort
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 !?
-
Feb 18th, 2011, 03:45 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|