-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyandex_script_1.py
More file actions
31 lines (21 loc) · 1.11 KB
/
yandex_script_1.py
File metadata and controls
31 lines (21 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
opt = webdriver.ChromeOptions()
opt.add_argument("start-maximized")
driver = webdriver.Chrome(executable_path='chromedriver.exe', options=opt)
# Переходим на яндекс
driver.get('https://yandex.ru')
driver.implicitly_wait(5)
#Ищем строку поиска, вводим
search = driver.find_element_by_xpath("//*[@class='input__control input__input']")
search.send_keys('Тензор tensor.ru')
#Проверяем таблицу с подсказками
suggest = driver.find_element_by_xpath("//*[@class='suggest2__content suggest2__content_theme_normal']")
# Нажимаем ENTER
search.send_keys(Keys.ENTER)
# Проверяем, что результаты поиска есть
results = driver.find_element_by_xpath("//*[contains(@class, 'serp-list serp-list_left_yes')]")
# Проверяем, что первая ссылка - сайт Тензора
first_result = driver.find_element_by_xpath("//*[@class = 'serp-item'][1]//*[@href='https://tensor.ru/']")
driver.close()