Home:ALL Converter>How to fix ChromeDriver that does not open Chrome?

How to fix ChromeDriver that does not open Chrome?

Ask Time:2021-09-22T05:37:07         Author:kiwi

Json Formatter

so I found a code online, it shows no errors, but when I start the code, even Chrome isn't opening. After a few seconds code ends running. I dont know how to solve this problem so if some of you can help me, I would be pleased. Note : I have the right version of ChoromeDriver installed.

from concurrent.futures.thread import ThreadPoolExecutor
from os import link
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
import random
import string
import re

chromeOptions = Options()
chromeOptions.headless = False # как будет запускаться хром - в фоне или нет
executor = ThreadPoolExecutor(20)  # количество одновременных потоков


def generate_random_string(length):
    letters = string.ascii_lowercase
    rand_string = ''.join(random.choice(letters) for i in range(length))
    return rand_string


# простейшая функция выгрузки всех ссылок с заданой страницы
def getlinks(url):
    driver = webdriver.Chrome(rpath='chromedriver.exe', options=chromeOptions)
    # path к chromedriver
    list = []
    driver.get(url)
    a = driver.find_elements_by_xpath('.//a')
    i = 0
    for b in a:
        i = i + 1
        link = b.get_attribute("href")
        list.insert(i, link)
    driver.quit()
    return list


def scrape(url, scraper=None):
    executor.submit(scraper, url)
    executor.submit(scraper, 'a link' +generate_random_string(10))

    # генерируем мусорные ссылки, если надо. кстати, если в тестируемом сайте
    # есть функция поиска или любые другие страницы с тяжелыми запросами в БД,
    # этот вариант - твой

    def scraper(url):
        driver = webdriver.Chrome(rpath='chromedriver.exe', options=chromeOptions)
        # path к chromedriver
        driver.get(url)
        time.sleep(15)
        driver.quit()

    urls = getlinks('a link')
    for url in urls * 10:  # количество инстансов
        scrape(url)

Where 'a link' is written there meant to be the target link. I have Selenium and ChromeDriver installed in the directory of the project. Thank you.

Author:kiwi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275823/how-to-fix-chromedriver-that-does-not-open-chrome
yy