Results 1 to 6 of 6

Thread: Best way to parse incoming html data

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2013
    Posts
    24

    Best way to parse incoming html data

    Hello guys,

    I'm trying to get the incoming data using winsock data arrival,but there are tons of html codes. Here is the visual look of what i want to parse.

    Name:  tracking.jpg
Views: 171
Size:  23.5 KB

    1. David_707 = my nick name
    2. 002381453 = my id number
    3. Delivered = state of the package
    4. The large message about the item
    5. 14:41:12 = Time
    6. 01Oct 2013 = the date when the item was delivered.

    there are 6 data i need to parse and get them listed on the Listview.

    Here i the html code:

    Code:
    <tbody><tr><td class="msg_date"><div class="date_div english light_gray"><span class="xlarge">01</span><span class="date_month">Oct<br>2013</span><span class="clear_line"></span><span class="date_time">14:41:12</span></div></td><td class="msg_img"><img src="images/default_gender_1.gif" class="sms_contact_image"></td><td class="msg_body"><p class="message_list_recipient english"><span class="red">David_707</span><span class="gray">(002381453)</span>&nbsp;&nbsp;&nbsp;<img src="images/small_arrow.gif">&nbsp;&nbsp;&nbsp;<span class="medium gray">Delivered</span></p><p class="msg_text english">The HP EliteBook 2540p laptop has been customized by the seller, so read the detailed listing and feel free to reach out to the seller to ask questions about specific adjustments. Without any modifications, this customized laptop is available in Intel Core i5 or Intel Core i7 processor to ensure faster computing speed. </p></td><td class="msg_tools"><div class="check_message_entry"><input type="checkbox" onchange="checkMessage(this)" id="check_list_item"></div><div onclick="changeFavorite(this)" class="star_btn" id="st_0"><a title="ფავორიტებში დამატება" class="east"><img src="images/star_gray.gif"></a></div><div onclick="deleteAction(this)" class="remove_message_entry" id="remove_list_item" style="display: none;"><img src="images/close.gif"></div></td></tr></tbody>
    And now, what i'm doing is :

    1. Getting data through winsock data arrival
    2. Parse them separately (using timer)
    3. generate them on the listview also with timers.

    I think there could be some easy way of doing that Here is my winsock code:

    Code:
    Private Sub Winsock5_DataArrival(ByVal bytesTotal As Long)
    Dim Data As String
    Dim data4 As String
        Dim beg As Long
        Dim data3 As String
        Dim tmfin As Long
        Dim hx As Long
        Dim a As Long
        Winsock5.GetData Data
        data4 = data4 & Data
    
    
    Dim Lista As ListView
    
    Dim dStart As Integer
    Dim dEnd As Integer
    
    
    Do While InStr(data4, "</span></p>") > 0
        dStart = InStr(data4, Chr(34) & "medium gray" & Chr(34) & ">") + 14
        dEnd = InStr(data4, "</span></p>")
        If dEnd > dStart Then
            psddata = Mid(data4, dStart, dEnd - dStart)
    
        
            data4 = Mid(data4, dEnd + 14)
            Else
            MsgBox "Error!"
            Exit Do
        End If
       
            Loop
    End Sub
    Then i'm using timer this way:

    Code:
    Private Sub Winsock5_SendComplete()
    Timer1 = True
    End Sub
    Here is my timer code:

    Code:
    Private Sub Timer1_Timer()
    Dim a As Integer
    Dim hx As Integer
    hx = ListView1.ListItems.Count
        For a = 1 To hx
            If ListView1.ListItems.Item(a).Text > 0 Then
           ListView1.ListItems.Item(a).SubItems(1) = psddata
    End If
     Next
    End Sub
    Too complicated right? give me an advice guys How to improve this **** and what to do in order to get those 6 data i need but with less code

    thanks in advance

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to parse incoming html data

    Code:
    Private data4 As String
    Private data5 As String
    
    Private Sub Winsock5_Connect()
     data4 = ""
    End Sub
    
    Private Sub Winsock5_Close()
     Dim beg As Long
     Dim data3 As String
     Dim tmfin As Long
     Dim hx As Long
     Dim a As Long
    
     Dim Lista As ListView
    
     Dim dStart As Integer
     Dim dEnd As Integer
    
     Do While InStr(data4, "</span></p>") > 0
       dStart = InStr(data4, Chr(34) & "medium gray" & Chr(34) & ">") + 14
       dEnd = InStr(data4, "</span></p>")
       
       If dEnd > dStart Then
         psddata = Mid(data4, dStart, dEnd - dStart)
         data5 = Mid(data4, dEnd + 14)
       Else
         MsgBox "Error!"
         Exit Do
       End If
     Loop
    End Sub
    
    Private Sub Winsock5_DataArrival(ByVal bytesTotal As Long)
     Dim Data As String
        
     Winsock5.GetData Data
     data4 = data4 & Data
    End Sub
    Last edited by jmsrickland; Nov 1st, 2013 at 03:37 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2013
    Posts
    24

    Re: Best way to parse incoming html data

    thanks jmsrickland. i will try that but I'm using timer to add data to listview and is it necessary to use timer? Is it possible just to add the data directly to litview on winock actions??

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Best way to parse incoming html data

    Is there any particular reason why you're using Winsock rather than the Inet or WebBrowser controls ?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2013
    Posts
    24

    Re: Best way to parse incoming html data

    Quote Originally Posted by Doogle View Post
    Is there any particular reason why you're using Winsock rather than the Inet or WebBrowser controls ?
    Yes. i'm newbie and right now, i only know +- how to use winsock :S Is it posible to do the same thing with the inet control??

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to parse incoming html data

    Using the INet control will only get you the source code just like you got using Winsock. You will still need to parse through it

    Put a Inet control on your Form

    This only replaces Private Sub Winsock5_DataArrival(ByVal bytesTotal As Long)

    Code:
      '
    Private data4 As String 
      '
      '
    Private Sub GetData()
     data4 = Inet1.OpenURL("http://www.the_web_site.com/the_file_", icString)
    End Sub
      '
      '
    Since you did not provide where you got your source data I just used place setters


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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