Skip to content

Instantly share code, notes, and snippets.

@andy23512
Last active April 19, 2020 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy23512/e1dab849c1eb10ee8bf3bcc8f3756835 to your computer and use it in GitHub Desktop.
Save andy23512/e1dab849c1eb10ee8bf3bcc8f3756835 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
driver = webdriver.Chrome()
action = ActionChains(driver);
driver.get("https://aqicn.org/city/shanghai/hk")
driver.execute_script("window.scrollTo(0, 2500);")
driver.implicitly_wait(10)
time.sleep(10)
element = driver.find_element_by_xpath("//*[@class='yearly-aqi']")
species = element.find_elements_by_xpath("//ul//li")
for specie in species:
print(specie.get_attribute("innerText"))
action.move_to_element(specie).perform()
time.sleep(2)
element = driver.find_element_by_xpath("//*[@class='yearly-aqi']")
print(element.get_attribute("innerHTML"))
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment