返回

excel-使用Selenium为Google Chrome创建对象

发布时间:2022-08-14 19:55:13 228

我继承了下面的代码,并希望将其用于谷歌浏览器,而不是IE,因为IE不再受支持。我已经下载了Selenium,但可能需要帮助将其转换为兼容。

Private Sub CommandButton1_Click()
    Application.Wait (Now + TimeValue("0:00:03"))
    Application.Calculation = xlCalculationManual
    
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.Visible = False
    
    i = 2
    
    Do Until IsEmpty(Cells(i, 1))
        'Will run until column A is empty
        Dim pageurl As String
        pageurl = Cells(i, 2).Value
        'set pageurl to value in Column B
        On Error Resume Next
        
        ie.Navigate pageurl
        'Do While ie.ReadyState <> READYSTATE_COMPLETE
        Application.Wait (Now + TimeValue("0:00:05"))
        'Do while loop was causing macro to stall and so added application wait time
        'Loop
        Dim x As String
        x = ie.Document.getElementsByClassName("lastUpdated")(0).outerText
        
        If x = "" Then x = ie.Document.getElementsByClassName("lastUpdated").innerText
        
        Cells(i, 3).Value = x
        'Replace value in Column C with Last Updated or no value
        x = ""
        i = i + 1
    Loop
    Application.Calculation = xlCalculationAutomatic
End Sub
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
相关帖子