這是我的代碼,然而當我開始運行它時,Firefox打開了,但沒有導航到該網站。如果我嘗試手動輸入URL,它仍然不顯示代理的IP地址。
from selenium import webdriver
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities["marionette"] =True
PROXY = "40.91.94.165:3128"/span>
firefox_capabilities["proxy"] = {
"proxyType": "MANUAL",
"httpProxy": PROXY。
"ftpProxy": PROXY。
"sslProxy": PROXY。
}
driver = webdriver.Firefox(capabilities=firefox_capabilities)
driver = webdriver.Firefox()
driver.get("https://wtfismyip.com")
這是我試圖停止它時得到的錯誤
^CTraceback (most recent call last):
檔案"/Users/****/Developer/python/proxy.py",行16,in <module>
driver = webdriver.Firefox(capabilities=firefox_capabilities)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/selenium/webdriver/firefox/webdriver.py", 行 170, in __init__
RemoteWebDriver.__init__(
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/selenium/webdriver/remote/webdriver.py", 行 157, in __init__
self.start_session(capabilities, browser_profile)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/selenium/webdriver/remote/webdriver.py",行 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/selenium/webdriver/remote/webdriver.py",行 319,in execute
response = self.command_executor.execute(driver_command, params)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/selenium/webdriver/remote/remote_connection.py", 行 374, in executive
return self._request(command_info[0], url, body=data)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/selenium/webdriver/remote/remote_connection.py", 行 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/urllib3/request.py", line 79, in request
return self.request_encode_body(
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/urllib3/request.py",行171,in request_encode_body
return self.urlopen(method, url, **extra_kw)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/urllib3/poolmanager.py", 行 330, 在urlopen
回應 = conn.urlopen(method, u.require_uri, **kw)
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/urllib3/connectionpool.py", 行 665, inurlopen
httplib_response = self._make_request(
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/urllib3/connectionpool.py", 行 421, in _make_request
six.raise_from(e, None)
檔案 "<string>", line 3, in raise_from
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/Site-packages/urllib3/connectionpool.py", 行 416, in _make_request
httplib_response = conn.getresponse()
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", 行 1347, in getresponse
回應.開始()
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 307, in begin
版本,狀態,原因 = self._read_status()
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", 行 268, in _read_status
line = str(self.fp.readline(_MAXLINE 1), "iso-8859-1" )
檔案 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socket.py", 行 669, 在 readinto
return self._sock.recv_into(b)
uj5u.com熱心網友回復:
我的解決方案是用一個與你不同的方法。 當我想做類似的事情時,我使用Chrome瀏覽器,但為了幫助你,我嘗試使用Firefox。
因此,我的解決方案與你需要安裝的另外兩個軟體包一起作業。第一個是webdriver_manager,你可以這樣安裝它(請確保完全按照我這里的方法安裝)。pip install -U webdriver-manager。
第二個是selenium-wire,你可以像這樣安裝它 pip install selenium-wire
from seleniumwire import webdriver
from webdriver_manager.firefox import GeckoDriverManager
PROXY = "40.91.94.165:3128"/span>
代理 = {
'proxy': {
'http': "http://" f"{PROXY}"。
'https'。"http://" f"{PROXY}"。
}
}
options = webdriver.FirefoxOptions()
options.headless = False[/span]。
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()。
options=options, seleniumwire_options=proxy)
driver.get("https://wtfismyip.com")
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/318350.html
標籤:
上一篇:查找不在檔案中的模式的grep
