使用 Selenium 和 Edge Python 进行网页抓取时出现基本错误

Basic Error while web scraping using Selenium and Edge with Python

代码试验:

!pip install selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep
from datetime import datetime
import pandas as pd
errors = []
season = []

代码在加载之前运行良好。 当我编写以下代码时出现错误:

for id in range(46605, 46985):
my_url = f'https://www.premierleague.com/match/{id}'
option = Options()
option.headless = True
driver = webdriver.Edge(options=option)
driver.get(my_url)

弹出如下错误:

错误截图2:

使用基于 Chromium with v4.x您必须安装以下软件包:

  • msedge-selenium-tools:

    pip install msedge-selenium-tools
    
  • 代码块:

    from msedge.selenium_tools import Edge
    
    s = Service('/path/to/edge')
    driver = Edge(service=s)
    

要使用基于 Chromium with in 模式,您需要 EdgeOptions class.

  • 代码块:

    from msedge.selenium_tools import EdgeOptions
    from msedge.selenium_tools import Edge
    
    # make Edge headless
    edge_options = EdgeOptions()
    edge_options.use_chromium = True  # required to make Edge headless
    s = Service('/path/to/edge')
    driver = Edge(service=s, options=edge_options)