Results 1 to 4 of 4

Thread: I have page HTML stored in a variable... But I need to find a certain value in HTML

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    4

    I have page HTML stored in a variable... But I need to find a certain value in HTML

    Let's say I have the HTML string:
    HTML Code:
    <html>
    <head>
    </head>
    <body>
    <table>
    <tr>
    <td>Money: </td>
    <td>${VARIABLE1}</td>
    <td>${VARIABLE2}</td>
    <td>${VARIABLE3}</td>
    <td>${VARIABLE4}</td>
    </tr>
    </table>
    </body>
    </html>
    So I need to get from that string, a string that has:
    "Variable1: {VARIABLE1}
    Variable2: {VARIABLE2}
    Variable3: {VARIABLE3}
    Variable4: {VARIABLE4}"
    Thanks,
    Dan

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: I have page HTML stored in a variable... But I need to find a certain value in HT

    Not sure where your getting the text before the colon : from but if you want to get the text in between the <td> tags, which is the ${VARIABLE}s then check the link in my signature.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: I have page HTML stored in a variable... But I need to find a certain value in HT

    You could also use regular expression, something like this :

    VB.NET Code:
    1. Dim sRegex As New Regex("<td>\$(\{.*\})</td>")
    2. Dim matchCol As MatchCollection
    3.  
    4. If sRegex.IsMatch(RichTextBox1.Text) Then
    5.     matchCol = sRegex.Matches(HTMLString)
    6.     For Each m as Match in MatchCol
    7.         'Build your result here
    8.         'The value you are looking for is located in m.groups(1).ToString()
    9.     Next
    10. End If

    Have a look at the first link in my signature to have a better idea of the Regular Expressions syntax.
    Hope this helps.
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    4

    Re: I have page HTML stored in a variable... But I need to find a certain value in HT

    I got it figured out last night actually... My code was all 100% working, but I had the WebClient set to a 5 second timeout, so it would work some of the time but not all the time... It was so confusing because I thought what I was changing was causing the errors, but it was just the variable load time of the web page, so my VisualBasic code was right all along.
    Here's what I used:

    VisualBasic Code:
    1. Dim Labels() As String = {"Raised", "Spent", "Cash on Hand", "Debts"}
    2. PageHtml = GetHTML(CurrentIDURL)
    3.                 Split1 = Split(PageHtml, "$", -1)
    4.                 For x = 1 To 4
    5.                     y = x - 1
    6.                     Split2 = Split(Split1(x), "</td>", -1)
    7.                     FullTextFileString += Labels(y) + "~$" + Split2(0) + vbCrLf
    8.                 Next
    And then the full file is inside "FullTextFileString"

    Thanks for all of your help though!

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