如何在 VBA 中无头地制作 selenium Chromedriver 运行?
How to make selenium Chromedriver run headlessly in VBA?
我在 vba 中结合 selenium 编写了一些代码来解析一些电影标题和它从 torrent 站点发布的年份。我在我的爬虫中使用了 ChromeDriver
。当我执行我的脚本时,它会解析所需的字段。
现在,我的问题是:我怎样才能做到 headless
?在其他语言中,可以将选项添加到 driver 以执行如下操作:
chrome_options = Options
chrome_options.add_argument ("--headless")
chrome_options.add_argument ("--window-size=2160,3840")
driver = WebDriver.Chrome(chrome_options = chrome_options)
当谈到向 vba 添加选项以使其无头时,我卡住了。
这是我的基本方法(这是一个可行的方法,但浏览器可见):
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
任何有关使脚本 运行 无头的帮助,我们将不胜感激。提前致谢。
当我已经在 Florent B.
的评论中找到了可行的解决方案时,我认为我不应该让这个 post 打开18=] 无头.
完整脚本:
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
我在 vba 中结合 selenium 编写了一些代码来解析一些电影标题和它从 torrent 站点发布的年份。我在我的爬虫中使用了 ChromeDriver
。当我执行我的脚本时,它会解析所需的字段。
现在,我的问题是:我怎样才能做到 headless
?在其他语言中,可以将选项添加到 driver 以执行如下操作:
chrome_options = Options
chrome_options.add_argument ("--headless")
chrome_options.add_argument ("--window-size=2160,3840")
driver = WebDriver.Chrome(chrome_options = chrome_options)
当谈到向 vba 添加选项以使其无头时,我卡住了。
这是我的基本方法(这是一个可行的方法,但浏览器可见):
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
任何有关使脚本 运行 无头的帮助,我们将不胜感激。提前致谢。
当我已经在 Florent B.
的评论中找到了可行的解决方案时,我认为我不应该让这个 post 打开18=] 无头.
完整脚本:
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