Selenium using VBA

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
I would like to hide the driver while web scraping with Selenium, just like it is done with IE object ("IE.Visible = False"). Is there a way to do what I want?
 
So I haven't been able to recreate the error you referenced. Instead, I encountered a number of other errors in running the same code through Selenium which reminded me that Selenium can be pretty tempermental. Turns out that, in the intervening hour, I needed to update my ChromeDriver. All I can do is suggest that you check that your ChromeDriver matches your version of Chrome, and to try restarting your system. I did this, and then tried the following code, and it worked:

VBA Code:
Sub HeadlessSelenium_CD()
  
    Dim CD As Selenium.ChromeDriver
    Dim strHTML As String

    ' Instantiate Selenium through the ChromeDriver
    Set CD = New Selenium.ChromeDriver
  
    ' Run Selenium in Headless mode
    CD.AddArgument "--headless"
    CD.Start
  
    ' Navigate to the URL
    CD.Get "https://www.tokopedia.com/petanidaun/foliage-premium-plant-food-khusus-tanaman-hias-daun"
  
    ' Extract the HTML code of the website
    strHTML = CD.PageSource
  
    ' Print the HTML code to the Immediate Window
    Debug.Print strHTML
  
    CD.Close
    Set CD = Nothing

End Sub

I should also add that the target website looks to be a bit tricky - when I first tried accessing the site with my updated ChromeDriver, I didn't use headless mode, and it worked OK. But then when I tried to access it under headless mode, It produced the following HTML code:

HTML:
<html><head>
<title>Access Denied</title>
</head><body>
<h1>Access Denied</h1>
You don't have permission to access "http://www.tokopedia.com/petanidaun/foliage-premium-plant-food-khusus-tanaman-hias-daun" on this server.<p></p></body></html>

Let me know if you've managed to get ChromeDriver to run in headless mode.
I tried at another address
success
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Glad to hear it - so did the .AddArgument approach work for you?
 
Upvote 0
i tried ripping the whole list of products (millions of items). i believe it requires a cookie container to manage permissions. the cookie has multiple parameters and i am not going to pursue it any further. it would require a fair amount of tinkering to get it going. selenium may automate all of that but it is not something easy to do using XMLHTTP
 
Upvote 0

Forum statistics

Threads
1,223,604
Messages
6,173,312
Members
452,510
Latest member
RCan29

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