Results 1 to 6 of 6

Error Looping Selenium Web Scraping (pls help)

Threaded View

  1. #1
    Forum Contributor
    Join Date
    01-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    263

    Error Looping Selenium Web Scraping (pls help)

    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)
    Attached Files Attached Files
    Last edited by therealdees; 03-08-2022 at 06:21 AM.
    Pedro.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Web Scraping with Selenium and printing to PDF
    By mdolinger in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2022, 04:08 PM
  2. [SOLVED] Selenium Basic - Does anyone know if you can change user-agent in selenium basic?
    By 0o0o0 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2021, 03:18 AM
  3. [SOLVED] VBA Web Scraping /On Error Goto - RUN-TIME ERROR 91
    By Excel_000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2020, 05:47 PM
  4. HTML scraping with a help of Selenium
    By ChipsSlave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2018, 12:12 AM
  5. Looping error while reading in Access VBA code- error 3314
    By mls_newbee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2018, 03:14 PM
  6. could not get last element while looping through class name (web scraping)
    By shiva_raj in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-18-2017, 08:15 PM
  7. [SOLVED] Webpage scraping into Excel - Run-time error '438': Object doesn't support this property..
    By kaseyleigh in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-29-2014, 08:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1