Results 1 to 14 of 14

Thread: [RESOLVED] Writing IF statement to check for html class string

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Resolved [RESOLVED] Writing IF statement to check for html class string

    Hi Guys,

    I am writing the code as on if statement that if the html class has strings called "<a id=""rowTitle1""(.*?)</a>" then do something. In what property that come after pattern that I could check the string whether if it valid or not??





    Thanks,
    Mark

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Writing IF statement to check for html class string

    show us the code you have so far.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Writing IF statement to check for html class string

    Oh sorry, here it is:

    Code:
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Create a request for the URL.        
            Dim request As WebRequest = WebRequest.Create("http://tvlistings.zap2it.com/tvlistings/ZCSGrid.do?stnNum=17927&channel=149")
            ' If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials
            ' Get the response.
            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
            ' Display the status.
            Console.WriteLine(response.StatusDescription)
            ' Get the stream containing content returned by the server.
            Dim dataStream As Stream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            Dim pattern As String = "<a id=""rowTitle1""(.*?)</a>"
            Dim pattern1 As String = "<a id=""rowTitle2""(.*?)</a>"
    
    
    
            Dim matches1 As MatchCollection = Regex.Matches(responseFromServer, pattern)
            Dim m2 As Match = Regex.Match(responseFromServer, pattern)
    
    
            Dim StrArr1() As String = matches1(1).Value().ToString.Split("")
            Label1.Text = StrArr1(0).ToString.Substring(77)
    
    
     
        If matches1(1).Value.Contains("<a id=""rowTitle1""(.*?)</a>") Then
                MessageBox.Show("Yep, there is a string!")
            End If
    
            ' Cleanup the streams and the response.
            reader.Close()
            dataStream.Close()
            response.Close()
        End Sub


    I tried to get the string from responseFromServer, that's where the project are checking for the string from the web server whether if the string are valid or not. I am using with matches1.value method (thats I use to find the string and match it using with value). However, I have debugged the project and I clicked the button, but the messagebox doesn't show up. The string have a valid name I can sure of that so I don't know why it is not working! Any idea??



    Sorry, I have forgot to included the source code in my first post.

    Thanks,
    Mark

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Writing IF statement to check for html class string

    I went here
    http://www.codehouse.com/webmaster_tools/regex/

    I placed your pattern in the appropriate place and then I went to the website listed and copied pasted the source in the appropriate place. And then I clicked Evaluate. There were no matches.

    I am NOT a regex guru, so I wouldn't even attempt to use it till I had spent several weeks(months, years) using it. One of the regex people here can probably help you again, but at some point you need to spend some time learning it.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Writing IF statement to check for html class string

    There are matches if I use without if statement so there is NOTHING to do with the matches whether if the regx value valid are correct or incorrect. It got to do with the http request, where I wish to check the string from the html class. I am not very sure which method that I would use to check the string??




    Someone might know this, I hope that she/he will post better info than your previous post.


    Thanks,
    Mark

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Writing IF statement to check for html class string

    I put a breakpoint on the If statement in the following code:
    Code:
            If matches1(1).Value.Contains("<a id=""rowTitle1""(.*?)</a>") Then 'break here
                MessageBox.Show("Yep, there is a string!")
            End If
    Then in the debugger I did this:
    ?matches1(1).Value
    here is what is in matches1(1).Value
    "<a id="rowTitle1" class="zc-ssl-pg-title" href='/tv/sky-sports-news/EP00275036'>SKY Sports News</a>"

    FYI - the messagebox did not show.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Writing IF statement to check for html class string

    yeah, so how can i get the messagebox to show up that if the pattern string is valid then show up the messagebox??



    Thanks,
    Mark

  8. #8

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Writing IF statement to check for html class string

    I have found a error.

    Code:
    Conversion from string "<a id="rowTitle1"(.*?)</a>" to type 'Integer' is not valid


    Any idea how to fix this?

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Writing IF statement to check for html class string

    So I was looking around and found this:
    http://vbcity.com/forums/t/160429.aspx.
    read the next to last post by mwolfsheimer (mwolfsheimer) and the moderators response.

    FYI - http://www.zap2it.com/services/site/...,7891102.story has similar language in their copyright.

    I have reported this thread.
    Last edited by dbasnett; Dec 30th, 2009 at 07:58 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Writing IF statement to check for html class string

    I don't use the site I am working on regards to mwolfsheimer. I only uses zap2it.com for my personal use only, so why did you reported this thread for being an idiot?? I have done nothing wrong.



  11. #11
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Writing IF statement to check for html class string

    I only uses zap2it.com for my personal use only, so why did you reported this thread for being an idiot?? I have done nothing wrong.
    Well it seems that you are infriging zingzing's explicit copyright notice.

  12. #12
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Writing IF statement to check for html class string

    *EDIT*

    Didn't read everything...
    Last edited by mickey_pt; Dec 31st, 2009 at 12:02 PM.

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Writing IF statement to check for html class string

    Quote Originally Posted by mark108 View Post
    I don't use the site I am working on regards to mwolfsheimer. I only uses zap2it.com for my personal use only, so why did you reported this thread for being an idiot?? I have done nothing wrong.


    I reported it because I found you posting in another forum and the owner of the website had requested that the thread be locked because of violation of copyright. I assume the moderators here have looked, which is all I wanted, and decided that this thread is OK.

    You could avoid this in the future by removing references in your code.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Writing IF statement to check for html class string

    dbasnett, I only got round to it today, sorry for the delay, and keep up the good work!

    Mods, please have a look at this thread I closed at CG :

    http://www.codeguru.com/forum/showthread.php?t=489981
    VB.NET MVP 2008 - Present

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