Y
Y
Yurii Abraham2021-07-21 12:31:26
Python
Yurii Abraham, 2021-07-21 12:31:26

[WinError 10061] Connection not established because the destination computer rejected the connection request')) How to fix the error?

The first parsing of the page works, but when the second time the parse_el() function is run, it gives an error

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


options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--hide-scrollbars')
driver = webdriver.Firefox(executable_path="./geckodriver.exe", options=options)

def get_html(url):
    driver.get(url)
    get_source = driver.page_source
    driver.quit()
    return get_source
def get_content(html):
    soup = BeautifulSoup(html, "html.parser")
    items_e = soup.find_all("div", class_="product-head-text")
    price__ = soup.find_all("div", class_ = "product-right-part")
def parse_el (url):
    html = get_html(url)
    get_content(html)

if __name__ == '__main__':
    parse_el("https://eldorado.ua/uk/kondicioner-samsung-ar09-txhqasinua/p71285447/?sc_content=20781_r258v426")
    parse_el("https://eldorado.ua/uk/kondicioner-samsung-ar09-txhqasinua/p71285447/?sc_content=20781_r258v426")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
V Maz, 2021-07-21
@Yura_nu_davai_rabotai

Gentlemen, the solution to this problem is insanely simple.
Since the code was called via import, the assignment of variables outside the called functions was not carried out. According to this, you need to make of this

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--hide-scrollbars')
driver = webdriver.Firefox(executable_path="./geckodriver.exe", options=options)

def get_html(url):
    driver.get(url)
    get_source = driver.page_source
    driver.quit()
    return get_source

This is
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--hide-scrollbars')

def get_html(url):
    driver = webdriver.Firefox(executable_path="./geckodriver.exe", options=options)
    driver.get(url)
    get_source = driver.page_source
    driver.quit()
    return get_source

S
soremix, 2021-07-21
@SoreMix

Because the driver was closed after parsing the first page inget_html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question