-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeteo.py
More file actions
35 lines (26 loc) · 1.08 KB
/
meteo.py
File metadata and controls
35 lines (26 loc) · 1.08 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
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
# each time wait 2s, to load element
driver.implicitly_wait(2)
# open weather forecast search engine
driver.get('http://www.meteo.pl/um/php/gpp/search.php')
# input city name
driver.find_element_by_name('name').send_keys('Gdynia')
# click search
driver.find_element_by_xpath('/html/body/table/tbody/tr[5]/td[2]/table/tbody/tr/td[2]/input').click()
# find weather forecast for cities
driver.find_element_by_link_text('Gdynia').click()
# return all handle values of opened browser windows
handles = driver.window_handles
# for each site print handle and title
for h in handles:
driver.switch_to.window(h)
print(h)
print(driver.title)
# for the site with diagram accept privacy policy and screenshot the diagram
if driver.title == 'Meteorogramy - meteorograms':
driver.find_element_by_xpath('//*[@id="qc-cmp2-ui"]/div[2]/div/button[2]').click()
driver.save_screenshot("weather.png")
# quit session
driver.quit()