如何在自动WebDriver中设置Chrome代理

时间:2019-07-04 07:48:35

标签: google-chrome proxy selenium-chromedriver autoit

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sSession
Local $sDesiredCapabilities
SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://whoer.net/")
MsgBox(0,0,0)
_WD_DeleteSession($sSession)
_WD_Shutdown()

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": "true", "args": ["disable-web-security"], "proxy": {"proxyType":"manual","httpProxy":"3.83.95.178:8888","sslProxy":"3.83.95.178:8888","autodetect": "false"}}}}'
EndFunc

它直接出现在MsgBox上,whoer.net没有可见的Chrome窗口。我该怎么办?帮我!!谢谢!

1 个答案:

答案 0 :(得分:0)

FileWriteLine ( "pr.bat", "cls" )
Sleep(100)
FileWriteLine ( "pr.bat", "@Echo off " )
Sleep(100)
FileWriteLine ( "pr.bat", "color 0b" )
Sleep(100)
FileWriteLine ( "pr.bat", 'reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0x00000001 /f ' )
Sleep(100)
$Line1 = FileReadLine ( "proxy.txt",  1)
Sleep(200)
FileWrite ( "pr.bat", 'reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d ' )
Sleep(100)
FileWrite ("pr.bat", $Line1 )
Sleep(100)
FileWrite ( "pr.bat", ' /f ' ); 
Sleep(200)
Run(@ScriptDir & "\pr.bat")
Sleep(2000)
;RunWait(@ScriptDir & "\pr.bat");
FileClose(FileOpen("pr.bat", $FO_OVERWRITE))

然后打开任何文件夹,然后按F5(这是数据更新)。