From IE to Selenium and Chrome

equidna

New Member
Joined
Mar 31, 2015
Messages
1
Dear forum, I wish you can help me because I am struggling with this matter for some days. The website I'm scrapping does not accept Internet Explorer anymore, then I'm switching to Selenium and Chrome. The code is getting the data, but I find 2 problems:

First, it is pasting the new data over the previous one instead to do it under (I'm scrapping several pages for every type of product),

second, I don't know how to the Excel to paste the data in current sheet.

This was the previous code:
VBA Code:
    Sub aMonitores()

        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")
        With ie
        .Visible = False
       
        For i2 = 1 To 13
      
         Worksheets("aMonitores").Select
        .navigate "https://www.mediamarkt.es/es/category/_monitores-701179.html?page=" & (i2) & ""
        Application.Wait (Now + TimeValue("0:00:1"))
        Do
        DoEvents
        Loop Until ie.readyState = READYSTATE_COMPLETE
        Dim doc As HTMLDocument
        Set doc = ie.document
        While ie.readyState <> 4
        Wend
       
               On Error Resume Next
       
        Dim i As Integer
        For i = 0 To 11
            
   'product link, probably wrong class name
       
        Range("A7").Offset(i + (i2 * 12), 0).Value = doc.getElementsByClassName("ProductsListstyled__ProductContainer-a3dwak-1 kpaiIf")(0).getElementsByClassName("Linkstyled__StyledLinkRouter-sc-1drhx1h-2 hihJjl ProductListItemstyled__StyledLink-sc-16qx04k-0 dYJAjV")(i).href
  
   'actual data
  
        Range("D7").Offset(i + (i2 * 12), 0).Value = doc.getElementsByClassName("StyledBox-sc-1vld6r2-0 bncFqw StyledFlexBox-sc-1w38xrp-4 lmlWlG")(i).innerText
         
       
        Next i
        Next i2
       
'tell me how many products are exhibit on the web
       
        Range("B1").Value = doc.getElementsByClassName("Cellstyled__StyledCell-sc-1wk5bje-0 NLfJA")(0).getElementsByClassName("Typostyled__StyledInfoTypo-sc-1jga2g7-0 kTxGyM")(0).innerText
        Range("C1").Value = doc.getElementsByClassName("Cellstyled__StyledCell-sc-1wk5bje-0 NLfJA")(0).getElementsByClassName("Typostyled__StyledInfoTypo-sc-1jga2g7-0 bfsyWw")(0).innerText
                  
'count the data obtained

  Range("C2").Select
    ActiveCell.FormulaR1C1 = "=COUNTA(R[3]C[-2]:R[4998]C[-2])"
 Range("E2").Select
    ActiveCell.FormulaR1C1 = "=COUNTA(R[3]C[-2]:R[4998]C[-2])"
   
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=COUNTA(R[3]C[-2]:R[4998]C[-2])"
       
        ie.Quit
             Application.EnableEvents = True

    End With
   
End Sub


And this is the code:

VBA Code:
Option Explicit

Private cd As Selenium.ChromeDriver


Sub mm()

 Set cd = New Selenium.ChromeDriver

 Worksheets("aMonitores").Select

 Dim ws As Worksheet

 Dim i As Integer

 Dim i2 As Integer

For i2 = 1 To 13

 cd.Get "https://www.mediamarkt.es/es/category/monitores-179.html?page=" & (i2) & ""

 Dim clases As Selenium.WebElements

 Dim clase As Selenium.WebElement

On Error Resume Next

 For i = 1 To 12

 Set clases = cd.FindElementsByCss(".StyledBox-sc-1vld6r2-0.bncFqw.StyledFlexBox-sc-1w38xrp-4.lmlWlG")

 clases.Text.ToExcel  ThisWorkbook.Worksheets.Add.Range("A1")

Next i
Next i2

cd.Close

End Sub

I have tried different options such as:

- Substituting the CSS line in the original code
- Writing (i) after the CSS code

And many others I can't recall.

Thank you very much for your time

Also asked here From Explorer to Selenium and Chrome
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top