Results 1 to 9 of 9

Thread: [RESOLVED] [2008] Need help with: Parsing HTML

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Location
    London
    Posts
    164

    Resolved [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:
    1. Dim src As String
    2.         Dim net As New Net.WebClient()
    3.  
    4.         src = net.DownloadString("http://site.com")
    5.  
    6.         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
    Last edited by n00b scripter; Jan 26th, 2009 at 07:14 PM.

  2. #2
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Location
    London
    Posts
    164

    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Location
    London
    Posts
    164

    Re: [2008] Need help with: Parsing HTML

    Still need help

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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)
    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    Hyperactive Member su ki's Avatar
    Join Date
    Oct 2007
    Posts
    354

    Re: [2008] Need help with: Parsing HTML

    vb Code:
    1. output = RegularExpressions.Regex.Replace(source, "<span[^>]*>((?:(?!<span[^>]*>).)*?)</span>", "[\1]", RegexOptions.IgnoreCase)

  7. #7
    Hyperactive Member su ki's Avatar
    Join Date
    Oct 2007
    Posts
    354

    Re: [2008] Need help with: Parsing HTML

    danasegarane i m late in responding any way "n00b scripter"
    use any of the solution given

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2008] Need help with: Parsing HTML

    It is their wish
    Please mark you thread resolved using the Thread Tools as shown

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Location
    London
    Posts
    164

    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) Took me a few minutes to figure it out but I managed to find it
    Thank you

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