#Python Selenium - 解決requests沒辦法解決的問題
安裝Selenium
安裝Driver
以chrome為例子
簡單範例:
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
| from selenium import webdriver from selenium.webdriver.chrome.options import Options
chrome_options =Options() chrome_options.add_argument('--headless')
driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.ip2.sg/RPS/WP/CM/SearchFastP.aspx' driver.get(url)
keyWord = driver.find_element_by_name("ctl00$PlaceHolderMain$uclSimpleSearch$txtSearchText")
keyWord.clear()
keyWord.send_keys("nike")
action = ActionChains(driver)
idTarget = driver.find_element_by_id("slide-to-unlock-old")
action.click_and_hold(idTarget).perform()
action.move_by_offset(50,0)
action.release().perform()
|