Skip to content

Instantly share code, notes, and snippets.

@erjan
Created July 21, 2020 19:44
Show Gist options
  • Save erjan/3f2f8a21d72dee299f8185edbeca6922 to your computer and use it in GitHub Desktop.
Save erjan/3f2f8a21d72dee299f8185edbeca6922 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from datetime import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
news_url = 'https://tengrinews.kz/kazakhstan_news/direktor-shkolyi-organizovala-kyiz-uzatu-v-shu-408946/'
driver.get(news_url)
delay = 20 # seconds
try:
com_id = news_url.split('-')[-1][:-1]
print('-----------------------COMMENT ID ' + str(com_id))
# button_xpath = "//*[@id=" + "\"comments_" + com_id + "\"]/div[1]/ul/li[2]/span/span[1][text()= 'Показать комментарии ']"
button_xpath = "//*[@id=" + "\"comments_" + com_id + "\"]/div[1]/ul/li[2]/span/span[1]/text()"
show_comments_button = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, button_xpath)))
if show_comments_button.is_displayed():
show_comments_button.click()
# actions = ActionChains(driver)
# actions.move_to_element(show_comments_button).click().perform()
# show_comments_button =WebDriverWait(driver, delay).until(EC.element_to_be_clickable((By.XPATH, button_xpath))).click()
except TimeoutException:
print("Loading took too much time!")
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment