Answer the question
In order to leave comments, you need to log in
[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
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
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question