Home > database >  ImportError: cannot import name 'start_chrome' from 'selenium'
ImportError: cannot import name 'start_chrome' from 'selenium'

Time:01-19

I am have no idea how selenium works. I just want to scrap data. Here is my code

from helium import *
from bs4 import BeautifulSoup
import selenium
from selenium import start_chrome
    
start_url = 'http://quotes.toscrape.com/'
    
new = start_chrome(url= start_url, headless=True)
    
soup = BeautifulSoup(new.page_source, 'html.parser')
    
quotes = soup.find_all('div', {'class':'quote'})
    
    
for item in quotes:
    print(item.find('span', {'class':'text'}))

I am getting

Traceback (most recent call last):
  File "G:\Sarfi Projects\python\remaining_tasks\remaining_tasks\spiders\helium.py", line 1, in <module>
    from helium import *
  File "G:\Sarfi Projects\python\remaining_tasks\remaining_tasks\spiders\helium.py", line 4, in <module>
    from selenium import start_chrome
ImportError: cannot import name 'start_chrome' from 'selenium' (G:\Sarfi Projects\python\remaining_tasks\env\lib\site-packages\selenium\__init__.py)

Anyone can please help me. I am suffering from two days but getting same results

CodePudding user response:

There is no start_chrome module in selenium resource.
You should use this

from selenium import webdriver

Example of working code is:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 30)

url = "https://stackoverflow.com/"
driver.get(url)

CodePudding user response:

To initialize using Helium you need to:

from helium import *

start_url = 'http://quotes.toscrape.com/'
new = start_chrome(url= start_url, headless=True)

Note: You don't require the import from selenium import start_chrome


Incase you require ChromeOptions and DesiredCapabilities then you can:

from selenium.webdriver import ChromeOptions
from selenium.webdriver import DesiredCapabilities
  • Related