【问题标题】:Basic Error while web scraping using Selenium and Edge with Python使用 Selenium 和 Edge 与 Python 进行 Web 抓取时的基本错误
【发布时间】:2022-01-15 21:30:42
【问题描述】:

代码试验:

!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:

【问题讨论】:

  • 将代码/错误作为图像发布会使我们更难提供帮助。请编辑问题,并以纯文本形式包含所有代码和错误消息。

标签: python selenium web-scraping microsoft-edge microsoft-edge-chromium


【解决方案1】:

要将基于ChromiumSelenium 一起使用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,您需要EdgeOptions 类。

  • 代码块:

    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)
    

【讨论】:

  • 您能进一步帮助我吗?我已经转移到 chrome 而不是边缘,这个特定的代码块运行良好,但我面临一个新的 webdriver 问题。
  • @KaustavMallick 随意提出一个关于您的新要求的新问题。因此,贡献者将很乐意为您提供帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-14
  • 1970-01-01
  • 1970-01-01
  • 2019-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多