Results 1 to 7 of 7

Thread: Problem getting value between html tags

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow Problem getting value between html tags

    Hi all i have this application that loads html and it needs to search trough all the html and list the numbers between VALUE=" and "></td> .I mean i want to collect bold number :VALUE="3018"></td>.

    My program what it does now it outputs like this with some extra things:

    Code:
    http://localhost/new/player.php?song=,"album.php?show_albums,"3018","3019","3020","3021"
    but i want it to look like this this

    Code:
    http://localhost/new/player.php?song=3018,3019,3020,3021
    i tried many things i could not remove the extra album.php?show_albums, and extra " from output url . I be happy if some one help me fix these problems.I bolded importent part.Thanks

    Html code hast mane of this type of blocks
    VB Code:
    1. <tr>
    2.     <td align="center" scope="row">1</td>
    3.     <td align="center"><INPUT TYPE="Checkbox" NAME="song_id" ONCLICK="reviewSelection();" [B]VALUE="[/B]3018[B]"></td>[/B]
    4.     <td><a href="#" class="song_title" onclick="loadPlayer('3018');return false;"> my life
    5. </a> </td>
    6.     <td align="center">&nbsp;</td>
    7.     <td align="center">&nbsp;</td>
    8.   </tr>


    my code:

    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2.  
    3. Select Case Index
    4.     Case 0:
    5.         If txtURL.Text <> "" Then
    6.             RichTextBox1.Text = Inet1.OpenURL(txtURL.Text, icString)
    7.         End If
    8.    
    9.     Case 1:
    10.         End
    11. End Select
    12. End Sub
    13.  
    14.  
    15. Private Sub Command2_Click()
    16.  Dim sResult() As String, n As Long
    17.  
    18.               If GetLine(RichTextBox1.Text, "[COLOR=Red]VALUE=[/COLOR]", " [COLOR=Red]></td>[/COLOR] ", sResult) Then
    19.         ' Occurances were found and have been placed in the array
    20.      
    21.         Text1.Text = "http://localhost/new/player.php?song"
    22.  
    23.         For n = LBound(sResult) To UBound(sResult)
    24.           List1.AddItem sResult(n)
    25.           Text1.Text = Text1.Text & "[COLOR=Red],[/COLOR]" & Split(sResult(n), "=")(1)
    26.  
    27.         Next n
    28.        
    29.  
    30.                
    31.         '--------------- end of making url code
    32.        
    33.        
    34.     Else
    35.         ' No occurances were found
    36.     End If
    37. End Sub
    38.  
    39.  
    40.  
    41.  
    42. Private Function GetLine(ByVal sText As String, ByVal sStart As String, ByVal sEnd As String, ByRef sArr() As String) As Boolean
    43.     Dim lPos As Long, lEnd As Long, lCount As Long, sTemp() As String
    44.    
    45.     ReDim sTemp(100)
    46.    
    47.     lPos = InStr(1, sText, sStart, vbTextCompare)
    48.     Do While lPos
    49.         lEnd = InStr(lPos, sText, sEnd, vbTextCompare)
    50.         If lEnd Then
    51.         'Remove & sEnd from the below line.
    52.         'sTemp(lCount) = Mid$(sText, lPos, lEnd - lPos) & sEnd
    53.             sTemp(lCount) = Mid$(sText, lPos, lEnd - lPos)
    54.             lPos = InStr(lEnd, sText, sStart, vbTextCompare)
    55.         Else
    56.             sTemp(lCount) = Mid$(sText, lPos)
    57.             lPos = 0
    58.         End If
    59.         lCount = lCount + 1
    60.         If lCount > UBound(sTemp) Then ReDim Preserve sTemp(100 + lCount)
    61.     Loop
    62.  
    63.     If lCount > 0 Then
    64.         ReDim Preserve sTemp(lCount - 1)
    65.         sArr = sTemp
    66.     End If
    67.     GetLine = lCount
    68. End Function

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Problem getting value between html tags

    You can use string functions to achieve your goal:
    VB Code:
    1. Dim a As String, f As String
    2. Dim b As Integer, e As Integer
    3. a = "http://localhost/new/player.php?song=,""album.php?show_albums,""3018"",""3019"",""3020"",""3021"""
    4. b = InStr(1, a, "=")
    5. e = InStr(2, Mid$(a, b + 1, Len(a) - b), ",")
    6. f = Left$(a, b) & Replace(Mid$(a, b + e + 1, Len(a) - b - e), """", "")
    7. Debug.Print f

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem getting value between html tags

    thank u for u reply. But the integer values at the end of constructed url is not know before hand!!

    I want my program to just get those intgers and put them in my constructed url as shown above:-( .

    My program already collection the integer values for for some reason i gets some extra thing (may be there is similer pattern in my html VALUE="..... "></td> and it has album.php?show_albums). i tried to do like this by loooking at intgers between this pattern :

    ONCLICK="reviewSelection();" VALUE="3027 "></td>

    to make unique .The way i did it by replacing this line :


    VB Code:
    1. If GetLine(RichTextBox1.Text, "VALUE=", " ></td> ", sResult)

    by

    VB Code:
    1. If GetLine(RichTextBox1.Text, "ONCLICK="reviewSelection();" VALUE=" ", " ></td> ", sResult)


    but it gives me strange errors!!



    In addition my constructed url contains this " between song ids and i do not how to remove thme from my constructed url!

    I hope some one help me.Thanks


    part of html blocks
    VB Code:
    1. ................
    2. <tr>
    3.     <td align="center" scope="row">10</td>
    4.     <td align="center"><INPUT TYPE="Checkbox" NAME="song_id" ONCLICK="reviewSelection();" VALUE="3027 "></td>
    5.     <td><a href="#" class="song_title" onclick="loadPlayer('3027');return false;">Shab bakhair
    6. </a> </td>
    7.     <td align="center">&nbsp;</td>
    8.     <td align="center">&nbsp;</td>
    9.   </tr>
    10.   <tr>
    11.  
    12.  
    13. .....
    Last edited by tony007; Apr 29th, 2006 at 12:15 PM.

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Problem getting value between html tags

    Try it like this instead:

    VB Code:
    1. If GetLine(RichTextBox1.Text, "VALUE=""", """></td>", sResult) Then
    2.         ' Occurances were found and have been placed in the array
    3.      
    4.         Text1.Text = "http://localhost/new/player.php?song="
    5.  
    6.         For n = LBound(sResult) To UBound(sResult)
    7.           List1.AddItem sResult(n)
    8.           Text1.Text = Text1.Text & Split(sResult(n), "=""")(1) & IIf(n = UBound(sResult), vbNullString, ",")
    9.         Next n

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem getting value between html tags

    Thanks for u reply . i tried your code but it only removes the " from output url but still i get unwanted data inside my constructued url !!

    My program what it does now it outputs like this with some extra things:

    Code:
    http://localhost/new/player.php?song=,"album.php?show_albums,"3018","3019","3020","3021"
    but i want it to look like this this

    Code:
    http://localhost/new/player.php?song=3018,3019,3020,3021

    My program already collects the integer values but for some reason i get some extra thing (may be there is similer pattern in my html VALUE="..... "></td> and it has album.php?show_albums).

    i tried to do like this by loooking at intgers between this pattern :

    ONCLICK="reviewSelection();" VALUE="3027 "></td>

    to make unique .The way i did it by replacing this line :


    VB Code:
    1. If GetLine(RichTextBox1.Text, "VALUE=", " ></td> ", sResult)

    by

    VB Code:
    1. If GetLine(RichTextBox1.Text, "[B]ONCLICK="reviewSelection();" VALUE= [/B] " ", " [B]></td>[/B] ", sResult)

    but it gives me strange errors!!

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Problem getting value between html tags

    Try:

    VB Code:
    1. If GetLine(Text2.Text, "reviewSelection();""" & " VALUE=""", """></td>", sResult) Then

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem getting value between html tags

    Quote Originally Posted by bushmobile
    Try:

    VB Code:
    1. If GetLine(Text2.Text, "reviewSelection();""" & " VALUE=""", """></td>", sResult) Then

    Many thanks for u reply. I have difficulty setting the search pattern criaterial .Could tell me how to find data shown in bold in the following pattern.



    Code:
    <option value="album.php?show_albums=oldies&JALSA=294c58d2c91828eae51d39707dd7e793;allow=NO;mohim=Download">Old Songs</option>
    the bold part is changing i want to us them to construtt a full url.Thanks

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