无法在Selenium VBA脚本中使用代理

时间:2018-07-22 06:26:04

标签: vba excel-vba selenium web-scraping selenium-chromedriver

我用zip(*[iter(s)]*n)vba一起编写了一个脚本。如果我注释掉我可能错误地为selenium定义的那一行,脚本就可以正常工作。

如何使用proxy运行刮板?我进行了很多搜索,但找不到匹配项可以帮助我解决此问题。

这是我的尝试:

proxy

如果我执行该宏,它将引发错误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

1 个答案:

答案 0 :(得分:2)

如下所示,来自@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