-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeleniumTest.py
More file actions
38 lines (30 loc) · 1.06 KB
/
SeleniumTest.py
File metadata and controls
38 lines (30 loc) · 1.06 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
32
33
34
35
36
37
38
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
url = 'https://www.cwb.gov.tw/V8/C/'
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
# chrome_options.add_argument("--headless")
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome(options = chrome_options)
driver.get(url)
#select district
select_element = driver.find_element(By.XPATH, '//*[@id="home-select-town"]')
selectDistrict = Select(select_element)
selectDistrict.select_by_visible_name('中壢區')
#click button
button = driver.find_element(By.CLASS_NAME, 'btn.btn-default.btn-block.btn-sm')
button.click()
#page down
move = driver.find_element(By.TAG_NAME, 'body')
move.send_keys(Keys.PAGE_DOWN)
time.sleep(1)
r = requests.get(driver.current_url)
result = r.text
print(result)
driver.quit()