|
-
Dec 30th, 2009, 12:04 PM
#1
Thread Starter
Banned
[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
-
Dec 30th, 2009, 12:09 PM
#2
Re: Writing IF statement to check for html class string
show us the code you have so far.
-
Dec 30th, 2009, 12:22 PM
#3
Thread Starter
Banned
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
-
Dec 30th, 2009, 01:42 PM
#4
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.
-
Dec 30th, 2009, 06:38 PM
#5
Thread Starter
Banned
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
-
Dec 30th, 2009, 07:14 PM
#6
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.
-
Dec 30th, 2009, 07:39 PM
#7
Thread Starter
Banned
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
-
Dec 30th, 2009, 07:48 PM
#8
Thread Starter
Banned
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?
-
Dec 30th, 2009, 07:55 PM
#9
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.
-
Dec 31st, 2009, 11:14 AM
#10
Thread Starter
Banned
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.
-
Dec 31st, 2009, 11:22 AM
#11
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.
-
Dec 31st, 2009, 11:31 AM
#12
-
Dec 31st, 2009, 11:39 AM
#13
Re: Writing IF statement to check for html class string
 Originally Posted by mark108
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.
-
Jan 5th, 2010, 01:20 AM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|