Python-Scraper с BS4 и Selenium: проблемы сеанса с ChromePython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Python-Scraper с BS4 и Selenium: проблемы сеанса с Chrome

Сообщение Anonymous »

Я пытаюсь получить список всех банков, которые расположены здесь, на этой странице
http://www.banken.de/inhalt/banken/fina ... tschland/1
примечание мы получили 617 результатов
мой подход: пойти и найти эти результаты – вкл. Сайт с использованием Python и Beautifulsoup из веб-драйвера импорта Selenium.

Код: Выделить всё

from bs4 import BeautifulSoup
import pandas as pd

# URL of the webpage
url = "http://www.banken.de/inhalt/banken/finanzdienstleister-banken-nach-laendern-deutschland/1"

# Start a Selenium WebDriver session (assuming Chrome here)
driver = webdriver.Chrome()  # Change this to the appropriate WebDriver if using a different browser

# Load the webpage
driver.get(url)

# Wait for the page to load (adjust the waiting time as needed)
driver.implicitly_wait(10)  # Wait for 10 seconds for elements to appear

# Get the page source after waiting
html = driver.page_source

# Parse the HTML content
soup = BeautifulSoup(html, "html.parser")

# Find the table containing the bank data
table = soup.find("table", {"class": "wikitable"})

# Initialize lists to store data
banks = []
headquarters = []

# Extract data from the table
for row in table.find_all("tr")[1:]:
cols = row.find_all("td")
banks.append(cols[0].text.strip())
headquarters.append(cols[1].text.strip())

# Create a DataFrame using pandas
bank_data = pd.DataFrame({"Bank": banks, "Headquarters": headquarters})

# Print the DataFrame
print(bank_data)

# Close the WebDriver session
driver.quit()
это возвращает (в моем плаще)

Код: Выделить всё

SessionNotCreatedException                Traceback (most recent call last)
 in ()
7
8 # Start a Selenium WebDriver session (assuming Chrome here)
----> 9 driver = webdriver.Chrome()  # Change this to the appropriate WebDriver if using a different browser
10
11 # Load the webpage

5 frames
/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
227                 alert_text = value["alert"].get("text")
228             raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 229         raise exception_class(message, screen, stacktrace)

SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from chrome location /root/.cache/selenium/chrome/linux64/124.0.6367.201/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5850d85e1e43 
#1 0x5850d82d04e7 
#2 0x5850d8304a66 
#3 0x5850d83009c0 
#4 0x5850d83497f0 
Ну, я думаю, мне нужно быть осторожным - на Colab не каждый селен будет работать безупречно

Подробнее здесь: https://stackoverflow.com/questions/787 ... ith-chrome
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»