Click elements on Zomato using Python Selenium Chrome Driver -
i trying gather submission time of reviews zomato. not ones "popular" tab ones "all reviews" tab.
for me have click "all reviews" tab having hard time doing , code keeps on printing ones "popular" tab.
output:
- 21 days ago
- one month ago
- one month ago
- 2 months ago
- 2 months ago
- 2 months ago
expected output:
- yesterday
- 4 days ago
- 4 days ago
- 13 days ago
- 14 days ago
note: output shows result of code day question posted.
from selenium import webdriver import os chromedriver = "....\\chromedriver" url = "https://www.zomato.com/cebu/the-pyramid-lahug-cebu-city" os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.chrome(chromedriver) driver.get(url) driver.find_elements_by_xpath("//a[@data-sort='reviews-dd']")[0].click() timelist = driver.find_elements_by_tag_name('time') time in timelist: print(time.text) driver.quit()
try piece of code may work.
from selenium import webdriver selenium.common.exceptions import timeoutexception selenium.webdriver.support.ui import webdriverwait # available since 2.4.0 selenium.webdriver.support import expected_conditions ec selenium.webdriver.common.by import selenium.webdriver.common.keys import keys import time browser=webdriver.chrome() browser.maximize_window() browser.get("https://www.zomato.com/cebu/the-pyramid-lahug-cebu-city") delay=15 #browser.execute_script("window.scrollto(0,document.body.scrollheight/2)") time.sleep(2) element = webdriverwait(browser, delay).until(ec.presence_of_element_located((by.xpath, ".//*[@id='selectors']/a[2]"))) element.click() element = webdriverwait(browser, delay).until(ec.presence_of_element_located((by.css_selector, ".item.default-section-title.everyone.empty"))) element.click() print "click done" time= webdriverwait(browser, delay).until(ec.presence_of_all_elements_located((by.css_selector, ".grey-text>time"))) in time: print i.text browser.quit()
Comments
Post a Comment