Merhaba arkadaşlar wp üzerinde buton var mı yokmu diye basit bir bot yazmaya çalışıyorum multi işlem yapan programımda selenium kullanıyorum ve hata alıyorum.
HATA :
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=50415): Max retries exceeded with url: /session/fcd2fe506ad3ac88e91ade5ba27d42a6/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000000038CEEB0>: Failed to establish a new connection: [WinError 10061] Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı'))
Kod:
def wpListecisi(url): # wp listeyi elde etmek için arama yapma
driver = webdriver.Chrome(service=ser, options=options)
driver.set_page_load_timeout(30)
try:
pageUrl = url
driver.get(pageUrl)
checkIfElementPresent = driver.find_elements(By.XPATH, '//*[@id="submit"]')
time.sleep(3)
driver.quit()
if len(checkIfElementPresent) != 0:
return pageUrl
except TimeoutException as e:
print("Hata verdi")
driver.quit()
driver.quit()
with ThreadPoolExecutor(max_workers=5) as executor:
for url in chromeListe:
processes2.append(executor.submit(wpListecisi, url))
for task in as_completed(processes2, timeout=15):
if task.result() != None:
wpListe.append(task.result())
print(task.result())
else:
print("------------------------------------------------------------------")
print(task.result())
print("------------------------------------------------------------------")
driver i try bloğunun içinde başlatırsamda bu sefer daha farklı hatalar alıyorum. Her iki durumdada Tarayıcı açık kalıyor kapanmıyor nasıl düzeltebilirim acaba.
Kod içerisinde listeden çekiliyor hocam listeyi eklemedim liste içerisinde çeşitli site urlleri var
kod içerisinde driver var hocam driver.quit()
başlahgıçta başlatıyorum işlemi fonksiyonun içerisinde görünüyor drivere atadığım.
options = webdriver.ChromeOptions()
ser = Service(ChromeDriverManager().install())
Hata kodunun tamamı:
Traceback (most recent call last):
File "C:/Users/Zeytin/PycharmProjects/wpAyristirici/main.py", line 127, in <module>
if task.result() != None:
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\_base.py", line 437, in result
return self.__get_result()
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\_base.py", line 389, in __get_result
raise self._exception
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:/Users/Zeytin/PycharmProjects/wpAyristirici/main.py", line 64, in wpListecisi
driver.close()
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 943, in close
self.execute(Command.CLOSE)
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 347, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 369, in _request
response = self._conn.request(method, url, body=body, headers=headers)
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\request.py", line 74, in request
return self.request_encode_url(
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\request.py", line 96, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\poolmanager.py", line 375, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 783, in urlopen
return self.urlopen(
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 783, in urlopen
return self.urlopen(
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 783, in urlopen
return self.urlopen(
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\Zeytin\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=50415): Max retries exceeded with url: /session/fcd2fe506ad3ac88e91ade5ba27d42a6/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000000038CEEB0>: Failed to establish a new connection: [WinError 10061] Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı'))
Process finished with exit code 1
Yaşadığım sorun daha geniş anlatayım çalıştırınca 5 tarayıcı açılıyor(max_workers=5) sitelere giriyor listede toplam 15 site var işlem yapılıp tamamlanınca kapanıp yeniden yeni url ile açılıyor ama bazen 1 tarayıcı bazen 3 tarayıcı asla kapanmıyor açık kalıyor ve program bu hatayı yolluyor. Şimdi sorun anladığım kadarı ile sayfa belirtilen sürede yüklenemeyince tarayıcının kapanması lazım (driver.set_page_load_timeout(30)) ama kapanmıyor kapanmadığı için ThreadPoolExecutor e geri dönüş sağlamıyor hal böyle olunca ThreadPoolExecutor aynı bağlantıyı tekrarlamaya çalışıyor buda hata vermesine neden oluyor ama bir çözüm üretemedim hocam.