我编写了一个python脚本来使用selenium登录wifi。
除非我没有登录到wifi,否则就无法上网。所以,我不能直接运行.install(),因为它试图访问互联网,但是失败了
样本代码:
from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager as dr_mngr
from subprocess import CREATE_NO_WINDOW
import os
os.environ['WDM_SSL_VERIFY'] = '0'
service = Service(dr_mngr().install())
service.creationflags = CREATE_NO_WINDOW
options = Options()
options.add_argument("--headless")
options.add_argument("--ignore-certificate-errors")
driver = webdriver.Edge(options=options, service=service)
driver.get("http://www.google.com")输出:
[WDM] - ====== WebDriver manager ======
[WDM] - Current edge version is 103.0.1264
[WDM] - Get LATEST edgedriver version for 103.0.1264 Edge
C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'msedgedriver.azureedge.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host '172.25.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
[WDM] - There is no [win64] edgedriver for browser 103.0.1264 in cache
[WDM] - Trying to download new driver from https://msedgedriver.azureedge.net/<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>
      Fortigate :: Login
    </title>
<!-- HTML Source Code of Login Page here -->
</html>/edgedriver_win64.zip
C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'msedgedriver.azureedge.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host '172.25.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
Traceback (most recent call last):
  File "C:\Users\VirtualBox\LogiNetwork\test.py", line 10, in <module>
    service = Service(dr_mngr().install())
  File "C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\webdriver_manager\microsoft.py", line 61, in install
    driver_path = self._get_driver_path(self.driver)
  File "C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\webdriver_manager\manager.py", line 24, in _get_driver_path
    binary_path = self.driver_cache.save_file_to_cache(driver, file)
  File "C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\webdriver_manager\driver_cache.py", line 32, in save_file_to_cache
    archive = save_file(file, path)
  File "C:\Users\VirtualBox\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\webdriver_manager\utils.py", line 37, in save_file
    os.makedirs(directory, exist_ok=True)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  [Previous line repeated 76 more times]
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\os.py", line 225, in makedirs
    mkdir(name, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Users\\VirtualBox\\.wdm\\drivers\\edgedriver\\win64\\<!DOCTYPE html PUBLIC "-'但是,当我在登录到Wifi之后运行这个程序时,它会从缓存中获取驱动程序并运行它。
发布于 2022-08-14 08:48:02
向项目添加静态驱动程序版本。
您将需要下载一个特定的版本并手动设置它,因此第一次运行将使用它。
try:
    # Connection check
    urllib.request.urlopen('www.google.com')
    driver = webdriver.Edge(dr_mngr().install())
except:
    # Connection failed
    driver = webdriver.Edge(r"path\chromedriver.exe")如果您的浏览器版本是动态的,那么您必须在脚本更新时提供一个新的驱动程序,或者将驱动程序版本设置为静态版本。
https://stackoverflow.com/questions/73349933
复制相似问题