Reputation: 22440
I've written some code in vba in combination with selenium to parse some movie titles and the year of its release from a torrent site. I used ChromeDriver
in my scraper. When I execute my script, It does parse the required fields.
Now, my question is: how can i make it headless
? In other languages there are the options which can be added to the driver to do the trick like below:
chrome_options = Options
chrome_options.add_argument ("--headless")
chrome_options.add_argument ("--window-size=2160,3840")
driver = WebDriver.Chrome(chrome_options = chrome_options)
When It comes to add the options to vba to make it headless, I get stuck.
This is my basic approach (It's a working one but browser is visible):
Sub Demo_Test()
Dim driver As New ChromeDriver, post As Object
driver.get "https://yts.am/browse-movies"
For Each post In driver.FindElementsByClass("browse-movie-bottom")
r = r + 1: Cells(r, 1) = post.FindElementByClass("browse-movie-title").Text
Cells(r, 2) = post.FindElementByClass("browse-movie-year").Text
Next post
End Sub
Any help on making the script run headless, will be highly appreciated. Thanks in advance.
Upvotes: 1
Views: 9633
Reputation: 22440
I don't think I should keep this post open when I've already got the working solution in comment by Florent B.
This is how we can make ChromeDriver
run headlessly.
The full script:
Sub Demo_Test()
Dim driver As New ChromeDriver, post As Object
With driver
.AddArgument "--headless" ''This is the fix
.get "https://yts.am/browse-movies"
End With
For Each post In driver.FindElementsByClass("browse-movie-bottom")
r = r + 1: Cells(r, 1) = post.FindElementByClass("browse-movie-title").Text
Cells(r, 2) = post.FindElementByClass("browse-movie-year").Text
Next post
End Sub
Upvotes: 3