Hi,
I used to run a code with internet explorer to scrape some ZIP codes from a site, but I'm trying to perform this task in Google Chrome by using Selenium. The code does work when I go step by step, but I get an error when it jumps to the next cell of the loop.
I'm using 'for each cell in selection' because I only need to scrape a few cells among a dataset. I'm not sure if that could be the issue, but if I could make it work that way it'd be great.
I added a sheet holding a few ZIP codes and the macro. Does anyone have a clue of what is going wrong?
Sub Scrapping_Correios()
Dim driver As New ChromeDriver
Dim keys As New Selenium.keys
Dim cell As Range
driver.Get "https://www.findcep.com/"
For Each cell In Selection
driver.FindElementsByClass("FindCepForm_input__3gHoo")(1).SendKeys (cell)
cell.Offset(0, 1) = driver.FindElementsByClass("FindCepForm_resultAddress__3L3TQ")(1).Value
cell.Offset(0, 2) = driver.FindElementsByClass("FindCepForm_resultAddress__3L3TQ")(2).Value
cell.Offset(0, 3) = driver.FindElementsByClass("FindCepForm_resultAddress__3L3TQ")(3).Value
cell.Offset(0, 4) = driver.FindElementsByClass("FindCepForm_resultAddress__3L3TQ")(4).Value
cell.Offset(0, 5) = driver.FindElementsByClass("FindCepForm_resultAddress__3L3TQ")(5).Value
Next cell
End Sub
PS: The website does not require a refresh to check for another ZIP code, it automatically updates the result whenever there's a change within the input/textbox. I haven't got that far, but I assume I'd have to delete the previous ZIP code before adding the next one, or it might just stack all of them sequently. I tried using .Clear, but nothing happens. I thought maybe I could use .SendKeys with CTRL + A and then Backspace (tried that too, but I guess I did it wrong, coz it didn't work either)
Bookmarks