Advertisement
Guest User

Request

a guest
Oct 26th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Request()
  2.  
  3.     Dim reqPart As Object
  4.     Set reqPart = CreateObject("WinHttp.WinHttpRequest.5.1")
  5.     reqPart.Open "GET", _
  6.         "http://www.bmfbovespa.com.br/indices/ResumoCarteiraTeorica.aspx?Indice=IBOVESPA&idioma=pt-br"
  7.        
  8.     reqPart.Send
  9.    
  10.     Dim reqPl As Object
  11.     Set reqPl = CreateObject("WinHttp.WinHttpRequest.5.1")
  12.     reqPl.Open "GET", _
  13.         "http://www.fundamentus.com.br/resultado.php"
  14.        
  15.     reqPl.Send
  16.    
  17.    
  18.     Dim i As Integer
  19.     Dim pos1 As Long
  20.     Dim pos2 As Long
  21.     Dim strPart As String
  22.     Dim strPl As String
  23.     Dim temp As String
  24.     Dim r1 As String
  25.     Dim r2 As String
  26.    
  27.     strPart = reqPart.ResponseText
  28.     strPl = reqPl.ResponseText
  29.    
  30.     Range("A2:C1000").Clear
  31.    
  32.     i = 2
  33.     Do While 1
  34.         pos1 = InStr(strPart, "lblCodigo")
  35.        
  36.         If (pos1 = 0) Then
  37.             Exit Do
  38.         End If
  39.        
  40.         strPart = Mid(strPart, pos1 + 9)
  41.        
  42.         pos1 = InStr(strPart, ">")
  43.         pos2 = InStr(strPart, "<")
  44.        
  45.         r1 = Mid(strPart, pos1 + 1, pos2 - pos1 - 1)
  46.        
  47.         Cells(i, 1).Value2 = r1
  48.        
  49.         pos1 = InStr(strPart, "lblPart_Formatada")
  50.         strPart = Mid(strPart, pos1 + 17)
  51.        
  52.         pos1 = InStr(strPart, ">")
  53.         pos2 = InStr(strPart, "<")
  54.        
  55.         r2 = Mid(strPart, pos1 + 1, pos2 - pos1 - 1)
  56.         r2 = Replace(r2, ",", ".")
  57.        
  58.         Cells(i, 2).Value2 = Val(r2)
  59.        
  60.         pos1 = InStr(strPl, "detalhes.php?papel=" & r1)
  61.         temp = Mid(strPl, pos1)
  62.         pos1 = InStr(temp, "<td>")
  63.         temp = Mid(temp, pos1 + 1)
  64.         pos1 = InStr(temp, "<td>")
  65.         temp = Mid(temp, pos1 + 4)
  66.         pos2 = InStr(temp, "<")
  67.        
  68.         r1 = Mid(temp, 1, pos2 - 1)
  69.         r1 = Replace(r1, ".", "")
  70.         r1 = Replace(r1, ",", ".")
  71.        
  72.         Cells(i, 3).Value2 = Val(r1)
  73.        
  74.         i = i + 1
  75.     Loop
  76.    
  77. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement