[PYTHON] selenium.common.exceptions.WebDriverException: Message: Processus fermé de manière inattendue avec l'état 1

Si vous obtenez une erreur comme celle-ci

    driver = webdriver.Firefox()
  File "/usr/local/pyenv/versions/3.6.8/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/pyenv/versions/3.6.8/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/pyenv/versions/3.6.8/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/pyenv/versions/3.6.8/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/pyenv/versions/3.6.8/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

Réécrire comme ça

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

Exemple

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
from time import sleep
import pandas as pd

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get('https://nikkei225jp.com/data/karauri.php')
sleep(5)
html = driver.page_source.encode('utf-8')
driver.close()

df_list = pd.read_html(html, header=0)
print(df_list[3].head())

résultat

Date Nikkei Cours moyen de l'action Nikkei Moyenne(changement)Volume de la première section de TSE(Millions d'actions)Ratio de vente à vide total Ratio de vente à vide(Il y a une réglementation des prix)Ratio de vente vide(Aucune restriction de prix)
0  2020-02-28  21142.96   -805.27          2420     44.5           36.9            7.6
1  2020-02-27  21948.23   -477.96          1811     47.4           40.4            7.0
2  2020-02-26  22426.19   -179.22          1677     46.0           38.1            7.9
3  2020-02-25  22605.41   -781.33          1778     44.5           34.8            9.7
4  2020-02-21  23386.74    -92.41          1155     43.5           37.0            6.5

Recommended Posts

selenium.common.exceptions.WebDriverException: Message: Processus fermé de manière inattendue avec l'état 1
Processus gaussien avec pymc3