try:
# Navigate to the xxxx site.
driver.get(“https://www.xxxx.com”)
# Click on an empty area on the site.
driver.find_element(By.XPATH, "//div[@class='container']").click()
# Scroll down to the bottom of the page.
for i in range(10): # adjust the range to scroll more or less.
driver.execute_script("window.scrollBy(0, 1000);")
sleep(1) # wait for 1 second.
print("Scrolled down to the bottom of the page")
# Scroll up to the top of the page.
for i in range(10): # adjust the range to scroll more or less.
driver.execute_script("window.scrollBy(0, -1000);")
sleep(1) # wait for 1 second.
print("Scrolled up to the top of the page")
except Exception as e:
print(f"Error: {e}")
Olmadı hocam herhangi bir tepki vermiyor.; işaretini kaldırıp öyle dener misin?
Olmadı hocam herhangi bir tepki vermiyor.
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Sildim dediğiniz gibi ekledim kaydırmıyor hocam.Bir de bu kodu dene. Ondan önce kaydırma kodlarını (for döngüleri) silip bunu koy ki, kaydırıp kaydrımadığını anlayabilesin.Python:driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
from time import sleep
import selenium.webdriver
from selenium.webdriver.common.by import By
driver = selenium.webdriver.Chrome()
try:
driver.get("https://www.technopat.net/sosyal/konu/selenium-4-webdriver-scroll-element-calismiyor.3312736/")
driver.find_element(By.XPATH, "//div[@class='p-body']").click()
for i in range(10):
driver.execute_script("window.scrollBy(0, 1000);")
sleep(1)
print("Scrolled down to the bottom of the page")
for i in range(10):
driver.execute_script("window.scrollBy(0, -1000);")
sleep(1)
print("Scrolled up to the top of the page")
except Exception as e:
print(f"Error: {e}")
Örnek olarak mynet diyelim hocam ona benzer bir kaç site de daha çalışması gerekiyor yardımcı olursanız çok sevinirim.Hangi sitede denediğinizi paylaşma imkânınız var mı?
Ben bu konunun sayfasında şu kodu denedim, çalışıyor:
Python:from time import sleep import selenium.webdriver from selenium.webdriver.common.by import By driver = selenium.webdriver.Chrome() try: driver.get("https://www.technopat.net/sosyal/konu/selenium-4-webdriver-scroll-element-calismiyor.3312736/") driver.find_element(By.XPATH, "//div[@class='p-body']").click() for i in range(10): driver.execute_script("window.scrollBy(0, 1000);") sleep(1) print("Scrolled down to the bottom of the page") for i in range(10): driver.execute_script("window.scrollBy(0, -1000);") sleep(1) print("Scrolled up to the top of the page") except Exception as e: print(f"Error: {e}")
from time import sleep
import selenium.webdriver
from selenium.webdriver.common.by import By
driver = selenium.webdriver.Chrome()
try:
driver.get("https://www.mynet.com/")
driver.find_element(By.XPATH, "//div[@class='container']").click()
for i in range(10):
driver.execute_script("window.scrollBy(0, 1000);")
sleep(1)
print("Scrolled down to the bottom of the page")
for i in range(10):
driver.execute_script("window.scrollBy(0, -1000);")
sleep(1)
print("Scrolled up to the top of the page")
except Exception as e:
print(f"Error: {e}")
Aslında kodun tamamını attım google'a giriyor mynet yazıyor daha sonra xpath kullanarak doğru siteye giriyor fakat log ekranında böyle bir hata var ama sistem çalışıyor bundan kaynaklı olabilir mi? Çünkü attığınız kod yine çalışmadı.Mynet'te de çalışıyor şu şekilde:
Python:from time import sleep import selenium.webdriver from selenium.webdriver.common.by import By driver = selenium.webdriver.Chrome() try: driver.get("https://www.mynet.com/") driver.find_element(By.XPATH, "//div[@class='container']").click() for i in range(10): driver.execute_script("window.scrollBy(0, 1000);") sleep(1) print("Scrolled down to the bottom of the page") for i in range(10): driver.execute_script("window.scrollBy(0, -1000);") sleep(1) print("Scrolled up to the top of the page") except Exception as e: print(f"Error: {e}")
Siz, kodunuzun tamamını paylaşmadınız. Belki öncesinde bir sıkıntı vardır.
Traceback (most recent call last):
File "c:\Users\Xtra\Desktop\test\DolphinController.py", line 100, in <module>
driver.find_element(By.XPATH, "//div[@class='container']").click()
File "C:\Users\Xtra\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 94, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\Xtra\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 395, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Xtra\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 354, in execute
self.error_handler.check_response(response)
File "C:\Users\Xtra\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div class="container">...</div> is not clickable at point (144, 38). Other element would receive the click: <nav class="my-menu-global">...</nav>
Aslında kodun tamamını attım...
... Google'a giriyor, Mynet yazıyor, daha sonra XPath kullanarak doğru siteye giriyor.
Çünkü attığınız kod yine çalışmadı.