|
-
December 18th, 2009, 08:45 PM
#1
Need help to get Regex.Match strings
Hi all,
I would like you to help me out with the strings, which I find it difficulty to get from the html class. The first string I uses as pattern1 string, which it connected to the server to get the showtitle string from the html class, it is working fine. I couldn't be able to get the string on the second paragraph from the html class with pattern2 string, as the text goes on the blank. I need to get the string from the html class. The third pattern string, I am trying to get the string at the end of the html class so I got the blank text.
Here it is the form code:
Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'Create a request for the URL.
Dim request As WebRequest = WebRequest.Create("http://blog.zingzing.co.uk/channels?channel=55")
' 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.
reader.Close()
dataStream.Close()
response.Close()
' Cleanup the streams and the response.
Dim pattern As String = "(?<=class=""showTitle""\>\<a href\=.+?""\>).+(?=\<\/a\>)"
Dim m As Match = Regex.Match(responseFromServer, pattern)
If m IsNot Nothing Then
Label2.Text = m.Value
End If
Dim pattern1 As String = "(?<=class=""showchannel""\>)"
Dim m1 As Match = Regex.Match(responseFromServer, pattern1)
If m1 IsNot Nothing Then
Label3.Text = m1.Value
End If
Dim pattern2 As String = "(1<<=class=""showTitle""\>>\<a href\=.+1""\>>).+(1=\<<\/a\>>)"
Dim m2 As Match = Regex.Match(responseFromServer, pattern2)
If m2 IsNot Nothing Then
Label4.Text = m.Value
End If
End Sub
I am trying to achieve my goal is to get the strings at the end of the html class. The code of html class for pattern1 string, I got from the website which here it is:
Code:
<p class="showchannel">Thursday 17th December, 11:00</p>
I want to get the string of the time at the end of the html class which it would be "11:00". That would be the one that come next to the comma. And for pattern2 string, I am trying to acheive my goal by getting the "showtitle" string on the second paragraph from the html class. You can still see that each paragraph on the below html code have the same name of the showtitle string as the first paragraph. I can get the showtitle string on the first paragraph , but the second paragraph I couldn't be able to get the showtitle string. I still only get the showtitle string from the first paragraph. I want to get the showtitle string on the second paragraph from the html class. If I use the same code to get the string for both paragraph as the first one and the second one then I will get the same string in each label text from the first paragraph. Here it is the html class I got it from the site:
Code:
1. <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/ywiyyt">Newsround</a></h3>
2. <p class="showChannel">Tuesday 15th December, 17:00</p>
3. <p class="showDescription">CBBC. Daily news magazine keeping young viewers up to date on the latest stories and events happening at home and abroad. <img src="http://vbcity.com/emoticons/emotion-56.gif" alt="Sleep"> 15min.</p>
4. <p class="showAiring">
5. <a href="http://blog.zingzing.co.uk/programmes?programme=96512182">More Airings</a>
6.
7. </p>
8. </div>
9.
10. <div class="showResult">
11. <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/n2zmmw">The Weakest Link</a></h3>
12. <p class="showChannel">Tuesday 15th December, 17:00, 17:15</p>
13. <p class="showDescription">Anne Robinson presents the quick-fire general knowledge quiz in which contestants must decide at the end of each round which of their number should be eliminated. <img src="http://vbcity.com/emoticons/emotion-56.gif" alt="Sleep"> 45min.</p>
14. <p class="showAiring">
15.
16. <a href="http://blog.zingzing.co.uk/programmes?programme=95683591">More Airings</a>
17. </p>
18. </div>
19.
20. <div class="showResult">
21. <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/njg2og">BBC News at Six</a></h3>
22. <p class="showChannel">Tuesday 15th December, 17:00, 18:00</p>
23. <p class="showDescription">The latest national and international news stories from the BBC News team, followed by Weather. <img src="http://vbcity.com/emoticons/emotion-56.gif" alt="Sleep"> 30min.</p>
24.
25. <p class="showAiring">
26. <a href="http://blog.zingzing.co.uk/programmes?programme=64544250">More Airings</a>
27. </p>
28. </div>
<h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/ywiyyt">Newsround</a></h3>
<p class="showChannel">Tuesday 15th December, 17:00</p>
<p class="showDescription">CBBC. Daily news magazine keeping young viewers up to date on the latest stories and events happening at home and abroad. Sleep 15min.</p>
<p class="showAiring">
<a href="http://blog.zingzing.co.uk/programmes?programme=96512182">More Airings</a>
</p>
</div>
<div class="showResult">
<h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/n2zmmw">The Weakest Link</a></h3>
<p class="showChannel">Tuesday 15th December, 17:00, 17:15</p>
<p class="showDescription">Anne Robinson presents the quick-fire general knowledge quiz in which contestants must decide at the end of each round which of their number should be eliminated. Sleep 45min.</p>
<p class="showAiring">
<a href="http://blog.zingzing.co.uk/programmes?programme=95683591">More Airings</a>
</p>
</div>
<div class="showResult">
<h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/njg2og">BBC News at Six</a></h3>
<p class="showChannel">Tuesday 15th December, 17:00, 18:00</p>
<p class="showDescription">The latest national and international news stories from the BBC News team, followed by Weather. Sleep 30min.</p>
<p class="showAiring">
<a href="http://blog.zingzing.co.uk/programmes?programme=64544250">More Airings</a>
</p>
</div>
I am trying very hard to be successful using with Regex.Match singular function, but I still have no luck yet.
I hope you guys can help!!!!!!!!!!
Thanks,
Mark
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
|