我環顧四周,還沒有找到在 excel 中使用 selenium 在 VBA 中使用 get 的方法。我試圖不打開瀏覽器,但仍然獲取 url 資訊。有誰知道在 vba 中使用硒來做到這一點的方法嗎?例如:
Option Explicit
Sub TestSelenium()
dim MyBrowser As Selenium.ChromeDriver
Set MyBrowser = New Selenium.ChromeDriver
MyBrowser.Start
driver.Get "https://www.google.com/"
End Sub
我已經看到了諸如 html 物件庫的方法
Option Explicit
Public Sub test()
'tools > references > Microsoft HTML Object Library
Dim html As MSHTML.HTMLDocument, xhr As Object
Set xhr = CreateObject("MSXML2.XMLHTTP")
Set html = New MSHTML.HTMLDocument
With xhr
.Open "GET", ""https://www.google.com/"", False
.setRequestHeader "User-Agent", "Safari/537.36"
.Send
html.body.innerHTML = .responseText
Debug.Print html.Title
End With
End Sub
但是,我對使用硒解決問題很感興趣。
uj5u.com熱心網友回復:
請為此用例使用無頭模式。
Dim driver As New ChromeDriver, post As Object
With driver
.AddArgument "--headless" ''This is the fix
.get "https://yts.am/browse-movies"
End With
uj5u.com熱心網友回復:
下載
https://phantomjs.org/download.html
并將exe添加到selenium中的正確檔案路徑
Sub HeadlessSelenium()
Dim PJSD As Selenium.PhantomJSDriver
Dim strHTML As String
' Instantiate Selenium through the PhantomJS Driver
Set PJSD = New Selenium.PhantomJSDriver
PJSD.Start
' Navigate to the URL
PJSD.Get "https://www.google.com/"
' Extract the HTML code of the website
strHTML = PJSD.PageSource
' Print the HTML code to the Immediate Window
Debug.Print strHTML
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/337305.html
上一篇:物體框架在插入后填充相關記錄
