Can't use proxy within selenium vba script

允我心安 提交于 2019-12-13 02:47:09

问题


I've written a script in vba in combination with selenium. The script does it's jobs just fine if I comment out the line I may have wrongly defined for proxy.

How can I run my scraper using proxy? I searched a lot but could not find a match that could help me solve this.

This is my try:

Sub UseProxy()
    Dim driver As New ChromeDriver, post As Object

    With driver
        .setProxy "38.131.10.78:53281"
        .get "https://stackoverflow.com/questions/tagged/web-scraping"
        For Each post In .FindElementsByCss(".question-hyperlink")
            R = R + 1: Cells(R, 1) = post.Text
        Next post
        .Quit
    End With
End Sub

If I execute the macro, It throws an error object doesn't support this method ------.


回答1:


As follows, from method by @Ulixestoitaca:

Option Explicit
Private Sub Use_Proxy()
    Dim d As WebDriver, post As Object, R As Long
    Set d = New ChromeDriver
    With d
        .Start
        .Proxy.SetHttpProxy "38.131.10.78:53281" 
        .get "https://stackoverflow.com/questions/tagged/web-scraping"

        For Each post In .FindElementsByCss(".question-hyperlink")
            R = R + 1: Cells(R, 1) = post.Text
        Next post

        .Quit
    End With
End Sub


来源:https://stackoverflow.com/questions/51462582/cant-use-proxy-within-selenium-vba-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!