Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使硒铬驱动在VBA中无头运行?_Vba_Selenium_Web Scraping_Selenium Chromedriver_Headless Browser - Fatal编程技术网

如何使硒铬驱动在VBA中无头运行?

如何使硒铬驱动在VBA中无头运行?,vba,selenium,web-scraping,selenium-chromedriver,headless-browser,Vba,Selenium,Web Scraping,Selenium Chromedriver,Headless Browser,我已经用vba和selenium编写了一些代码,用于解析一些电影标题及其在torrent网站上发布的年份。我在刮板中使用了ChromeDriver。当我执行脚本时,它会解析所需的字段 现在,我的问题是:我怎样才能使它无头?在其他语言中,有一些选项可以添加到驱动程序中,以执行以下操作: chrome_options = Options chrome_options.add_argument ("--headless") chrome_options.add_argument ("--window-

我已经用vba和selenium编写了一些代码,用于解析一些电影标题及其在torrent网站上发布的年份。我在刮板中使用了
ChromeDriver
。当我执行脚本时,它会解析所需的字段

现在,我的问题是:我怎样才能使它无头?在其他语言中,有一些选项可以添加到驱动程序中,以执行以下操作:

chrome_options = Options
chrome_options.add_argument ("--headless")
chrome_options.add_argument ("--window-size=2160,3840")
driver = WebDriver.Chrome(chrome_options = chrome_options)
当要将选项添加到vba以使其无头时,我会陷入困境

这是我的基本方法(这是一个可行的方法,但浏览器是可见的):


任何帮助使脚本运行无头,将不胜感激。提前感谢。

我认为我不应该在Florent B的评论中已经得到了工作解决方案之后继续发表这篇文章。这就是我们如何让
ChromeDriver
无头运行的方法

全文如下:

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

当我已经在Florent B的评论中得到了有效的解决方案时,我认为我不应该继续发表这篇文章。这就是我们可以让
ChromeDriver
无头运行的方法

全文如下:

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

尝试
driver.AddArgument”--headless“
,然后调用
driver.get”https://yts.am/browse-movies“
感谢Florent B.提供了如此出色的解决方案。请尝试
driver.AddArgument”--headless”
,然后调用
driver.get”https://yts.am/browse-movies“
感谢Florent B.提供了如此出色的解决方案。