Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wpforms-lite domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/ragipunal.com/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the businext domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/ragipunal.com/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the businext domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/ragipunal.com/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/ragipunal.com/wp-includes/functions.php on line 6114
Selenium WebDriver ile Google da aranılan kelimeden istenilen linki bulup ziyaret etme - RAGIP ÜNAL

Blog

Selenium WebDriver ile Google da aranılan kelimeden istenilen linki bulup ziyaret etme

Merhabalar;

Bu python kod parçaçığı ile google da arama yapar ve bulunan sonuçlarda 10 sayfa boyunca ilerler ve bulduğunda ise siteyi ziyaret eder.

author = 'rgpunal'
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep

if __name__ == "__main__":
    profile = webdriver.FirefoxProfile()
    profile.native_events_enabled = True

    driver = webdriver.Firefox(profile)
    driver.maximize_window()
    driver.implicitly_wait(15)
    wait = WebDriverWait(driver, 10)
    siteUrl = "ragipunal.com"
    searchEngineUrl = "http://www.google.com"

    maxPageNumber = 10

    driver.get(searchEngineUrl)
    inputElement = driver.find_element_by_name("q")
    inputElement.send_keys("ragıp ünal" + Keys.RETURN)
    pageNumber = 1
    flag = False
    while (not flag):
        linkElements = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//h3[@class='r']/a")))
        for toClick in linkElements:
            action = ActionChains(driver)
            action.move_to_element(toClick).perform()
            sleep(1)
            if (siteUrl in toClick.get_attribute("href")):
                action.click()
                flag = True
        if not flag:
            # Eğer max sayfa sayısını geçti ise döngüyü sonlandır.
            if pageNumber > maxPageNumber:
                break
            try:
                nextPage = wait.until(EC.element_to_be_clickable((By.XPATH,"//a[@id='pnnext']/span[1]")))
            except:
                break
            sleep(2)
            # Bu bölümde hareket kazandırıyoruz.
            action = ActionChains(driver)
            action.move_to_element(nextPage).perform()
            sleep(5)
            nextPage.click()
            pageNumber += 1
            pn = str(pageNumber)
            wait.until(EC.text_to_be_present_in_element((By.XPATH, "//td[@class='cur']"), pn))
    driver.quit()

Leave A Comment

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir