bangnaga

Parsing HTML (Jadwal Penerbangan/Ticketing)

Feb 27th, 2012
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim http As WinHttpRequest
  2.  
  3. Private Sub Command1_Click()
  4. Dim sTextHTML As String
  5. Set http = New WinHttpRequest
  6. http.Open "POST", "http://ayolagi.com/tiket/caritiket#konten", False
  7. http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  8. http.Send "data[Ticket][dari]=Makassar&data[Ticket][tujuan]=Jakarta+SOETA&data[Ticket][tglberangkat]=02-08-2012&list[1]=Garuda&list[2]=Lionair&list[3]=Batavia&list[4]=Merpati&list[5]=AirAsia&list[6]=Citilink"
  9. sTextHTML = http.ResponseText
  10. Hasil.Text = sTextHTML
  11.  
  12. Dim strStart As String, strEnd As String
  13. Dim strEmail As String
  14.  
  15. strStart = "('Jam keberangkatan');"
  16. strEnd = "</table>"
  17.  
  18. Hasil2.Text = ParsingData(Hasil.Text, strStart, strEnd)
  19. Hasil2.Text = ParsingData(Hasil2.Text, "<tbody>", "</tbody>")
  20. End Sub
  21.  
  22.  
  23. Public Function ParsingData(IStringStr As String, StrAwal As String, StrAkhir As String)
  24. On Error Resume Next
  25. Dim iString As String
  26. iString = IStringStr
  27. iString = Right(iString, Len(iString) - InStr(iString, StrAwal) - Len(StrAwal) + 1)
  28. iString = Mid(iString, 1, InStr(iString, StrAkhir) - 1)
  29. ParsingData = iString
  30. End Function
  31.  
  32.  
  33. Private Sub GetMaskapai()
  34. List1.Clear
  35. Dim StrField1() As String
  36. Dim StrField2() As String
  37.    Dim i As Integer
  38.    StrField1() = Split(Hasil2.Text, "tooltip.show(")
  39.      
  40.    Text1 = vbNullChar
  41.    For i = 1 To UBound(StrField1)
  42.        StrField1(i) = ParsingData(StrField1(i), "('", "')")
  43.        List1.AddItem StrField1(i)
  44.    Next i
  45.    Erase StrField1
  46. End Sub
  47.  
  48. Private Sub GetHarga()
  49. List2.Clear
  50. Dim StrField1() As String
  51. Dim StrField2() As String
  52.    Dim i As Integer
  53.    StrField1() = Split(Hasil2.Text, "right")
  54.      
  55.    Text1 = vbNullChar
  56.    For i = 1 To UBound(StrField1)
  57.        StrField1(i) = ParsingData(StrField1(i), ">", "<")
  58.        List2.AddItem StrField1(i)
  59.    Next i
  60.    Erase StrField1
  61. End Sub
  62.  
  63. Private Sub GetKeberangkatan()
  64. List3.Clear
  65. List4.Clear
  66. Dim StrField1() As String
  67. Dim StrField2() As String
  68.    Dim i As Integer
  69.    StrField1() = Split(Hasil2.Text, "left")
  70.        
  71.    Text1 = vbNullChar
  72.    For i = 1 To UBound(StrField1)
  73.        StrField1(i) = ParsingData(StrField1(i), ">", "<")
  74.        If i Mod 2 = 1 Then
  75.             List3.AddItem StrField1(i)
  76.         Else
  77.            List4.AddItem StrField1(i)
  78.         End If
  79.    Next i
  80.    Erase StrField1
  81. End Sub
  82.  
  83.  
  84. Private Sub Command3_Click()
  85. GetMaskapai
  86. GetHarga
  87. GetKeberangkatan
  88. End Sub
RAW Paste Data