[RESOLVED] [2008] Need help with: Parsing HTML
Hello.
I successfully wrote a code to retrieve a version number from a HTML page which is this code:
HTML Code:
<div class="header">Latest Version: <span class="version">6.59</span></div>
Using this code:
VB Code:
Dim src As String
Dim net As New Net.WebClient()
src = net.DownloadString("http://site.com")
version = src.Substring(InStr(src, "Latest Version:", CompareMethod.Text) + 33, 4)
So the following code will return the version number which currently is 6.59 which is what I'm after.
But then i remembered that releases are done as following: 6.59, 6.59b, 6.59c, 6.60, 6.60b etc.
So when the b version of 6.59 is released the parser will still return 6.59. So how can i make this code better?
Thank you
Re: [2008] Need help with: Parsing HTML
Try to change your code to get it to get the contents between
<span class="version">****</span>
then it would be easier to get the correct data, else you would have to change the current code so that it gets 5 chars instead of 4
(InStr(src, "Latest Version:", CompareMethod.Text) + 33, 4))
but that would just mess up depending on which type of version you release.
Could be version 6.35.4.5 which is alot more than 5 chars
Re: [2008] Need help with: Parsing HTML
Quote:
Originally Posted by Zeelia
Try to change your code to get it to get the contents between
<span class="version">****</span>
then it would be easier to get the correct data, else you would have to change the current code so that it gets 5 chars instead of 4
(InStr(src, "Latest Version:", CompareMethod.Text) + 33, 4))
but that would just mess up depending on which type of version you release.
Could be version 6.35.4.5 which is alot more than 5 chars
Well yeh I've understood that that's what I need to do. But I don't really know how to do it.
Re: [2008] Need help with: Parsing HTML
Re: [2008] Need help with: Parsing HTML
Hope this helps
Code:
Dim sPattern As String = "<span .*?>(.*?)</span>"
Dim src As String
Dim net As New Net.WebClient()
src = net.DownloadString("http://site.com")
MessageBox.Show(System.Text.RegularExpressions.Regex.Matches(src, sPattern).Item(0).Groups(0).Value)
Re: [2008] Need help with: Parsing HTML
vb Code:
output = RegularExpressions.Regex.Replace(source, "<span[^>]*>((?:(?!<span[^>]*>).)*?)</span>", "[\1]", RegexOptions.IgnoreCase)
Re: [2008] Need help with: Parsing HTML
danasegarane i m late in responding any way "n00b scripter"
use any of the solution given
Re: [2008] Need help with: Parsing HTML
Re: [2008] Need help with: Parsing HTML
Quote:
Originally Posted by danasegarane
Hope this helps
Code:
Dim sPattern As String = "<span .*?>(.*?)</span>"
Dim src As String
Dim net As New Net.WebClient()
src = net.DownloadString("http://site.com")
MessageBox.Show(System.Text.RegularExpressions.Regex.Matches(src, sPattern).Item(0).Groups(0).Value)
Worked perfect with Groups(1) :D Took me a few minutes to figure it out but I managed to find it :D
Thank you :thumb: