Avatar of tjgrindsted
tjgrindsted
 asked on

HTTPWeb Request/Response

Hi i have this code, that shows a soccer match ranklist.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim request As HttpWebRequest = CType(WebRequest.Create("http://www.dbu.dk/turneringer_og_resultater/resultatsoegning/position.aspx?poolid=135814"), 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="div2"></div>"
        Dim EndToken As String = "<div class="PageUnionInfo" id="PageUnionInfo" style="margin-bottom:4px;">"
        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 = intput.Substring(ContentStartPosition, Length)
        someLabel.Text = Content
    End Sub

Open in new window


this code will the ranking list.
My question is, if i need to find a targ/name maybe like "c01 first" and i need to go 8 steps after the name and then show the text from that place to the next "<" how do i do that in asp.net.

In asphttp i know that i can do it like this:

Read=instr(ReadEnd,strResult,"c01 first")+8
ReadEnd=instr(Read,strResult,"<")
Team1=mid(strResult,Read,ReadEnd-Read)

but how do i do it in ASP.NET !?
ASP.NETVB Script

Avatar of undefined
Last Comment
tjgrindsted

8/22/2022 - Mon
Luis Pérez

This is a port "as is" of your code to Vb.net. I think it will work without problems.

Dim Read As Integer = strResult.IndexOf("co1 first", ReadEnd) + 8
Dim ReadEnd As Integer = strResult.IndexOf("<", Read)
Dim Team1 As String = strResult.Substring(Read,ReadEnd-Read)

Hope that helps.
tjgrindsted

ASKER
Hi i have looked at it 3 days now, but im stuck...

If i use this code
Imports System.Net
Imports System.IO
Imports System.Text

Partial Class eks2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim objRequest As HttpWebRequest = WebRequest.Create("http://www.dbu.dk/turneringer_og_resultater/resultatsoegning/position.aspx?poolid=135814")
        Dim objResponse As HttpWebResponse = objRequest.GetResponse()
        Dim Output As String = ""
        Using reader = New StreamReader(objResponse.GetResponseStream(), Encoding.GetEncoding("iso-8859-1"))
            Output = reader.ReadToEnd()
        End Using

        Output = Output.Substring(Output.IndexOf("<div id=""div2""") + 21)
        Output = Output.Substring(0, Output.IndexOf("<div class=""PageUnionInfo"" id=""PageUnionInfo"" style=""margin-bottom:4px;"">"))

        Dim ReadEnd As Integer = ""
        Dim Read As Integer = ""
        Dim strResult As String Output.ReadToEnd()
        Read = strResult.IndexOf("poolid=", ReadEnd) + 15
        ReadEnd = strResult.IndexOf("<", Read)
        Dim Team1 As String = strResult.Substring(Read, ReadEnd - Read)

        someLabel.Text = Team1
        'It will writeout Varde IF  (1)

    End Sub

End Class

Open in new window


If u delete this part and the set someLable.Text = Output the i get the result table...
But when i add this part then i cant get the name Varde IF (1) from the output result
        Dim ReadEnd As Integer = ""
        Dim Read As Integer = ""
        Dim strResult As String Output.ReadToEnd()
        Read = strResult.IndexOf("poolid=", ReadEnd) + 15
        ReadEnd = strResult.IndexOf("<", Read)
        Dim Team1 As String = strResult.Substring(Read, ReadEnd - Read)

        someLabel.Text = Team1
        'It will writeout Varde IF  (1)

Open in new window


Hope u can help me !!
tjgrindsted

ASKER
Someone that can help me here !?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
tjgrindsted

ASKER
bump
ASKER CERTIFIED SOLUTION
tjgrindsted

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
tjgrindsted

ASKER
post closed
tjgrindsted

ASKER
post closed
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.