I need to search for information on a real estate site and bring it to excel. I made the macro below:
Sub zap()
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Navigate "http://www.zap.com.br/imoveis/fipe-zap/"
.Visible = True
End With
Do While ie.Busy
Loop
Do While ie.readyState <> 4
Loop
Call aguarda
Dim CurrentWindow As HTMLWindowProxy: Set CurrentWindow = ie.Document.parentWindow
'SELECIONA O NUMERO DE DORMITORIOS: (0)=Todos (1)=1 dormitório (2)=2 dormitórios (3)=3 dormitórios (4)=4 dormitórios
ie.Document.All.Item("ctl00$ContentPlaceHolder1$quartosFipe")(0).Checked = True
'SELECIONA O PERÍODO: (0)=Ano corrente (1)=Últimos 12 meses (2) =Todo o período
ie.Document.All.Item("ctl00$ContentPlaceHolder1$")(2).Checked = True
'SELECIONA SE É VENDA OU ALUGUEL: (0)=Venda (1)=Aluguel
ie.Document.All.Item("ctl00$ContentPlaceHolder1$radTransacao")(0).Checked = True
'SELECIONA A CIDADE: (0)=FipeZap Ampliado (1)=FipeZap Composto (2)=Belo Horizonte (3)=Brasilia (4)=Curitiba (5)=Florianopolis (6)=Fortaleza (7)=Niteroi (8)=Porto Alegre (9)=Recife (10)=Rio de Janeiro (11)=Salvador (12)=Santo Andre (13)=São Bernardo do Campo (14)=São Caetano do Sul (15)=São Paulo (16)=Vila Velha (17)=Vitoria
ie.Document.All.Item("ctl00$ContentPlaceHolder1$ddlCidadeIndiceFipeZap")(10).Selected = True
'ATUALIZA O GRÁFICO
ie.Document.parentWindow.execScript ("javascript:AtualizaGraficoIndice()")
For Each element In ie.Document.getElementsByTagName("circle")
x = element.getAttribute("cx")
y = element.getAttribute("cy")
Workbooks("FipeZap.xlsm").Worksheets("Plan1").Range("A1000000").End(xlUp).Offset(1, 0).Value = x
Workbooks("FipeZap.xlsm").Worksheets("Plan1").Range("B1000000").End(xlUp).Offset(1, 0).Value = y
Next
End Sub
Sub Awaits:
Sub aguarda()
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
End Sub
However, not all values returned by the site hit the values inspected in the chart. Although column B hits the values, the values in column A do not match either.
Does anyone know if it's a macro problem (I believe not) or am I letting some of the settings that ZAP Real Estate is doing on the page before plotting the chart?
Editing
Personal, the code just opens the ie, makes the selection of the criteria in the chart and inserts into excel.
Follow the debug image of the zap page and return the macro.
One of the information is not faithfully brought. See the screen below, the underlined information is brought correctly, while the information circled comes wrong.