基本使用方法
from selenium import webdriver # 瀏覽器驅動器
from selenium.webdriver import ActionChains # 拖動,滑動驗證
from selenium.webdriver.common.by import By #按照什麼方式查找,By.ID,By.CSS_SELECTOR
from selenium.webdriver.common.keys import Keys #鍵盤按鍵操作
from selenium.webdriver.support import expected_conditions as EC #場景判斷用的,一般和下面的等待加載元素一起使用
from selenium.webdriver.support.wait import WebDriverWait #等待頁面加載某些元素
browser=webdriver.Chrome()
try:
browser.get('https://www.baidu.com')
input_tag=browser.find_element_by_id('kw')
input_tag.send_keys('美女') #python2中輸入中文錯誤,字符串前加個u
input_tag.send_keys(Keys.ENTER) #輸入回車
wait=WebDriverWait(browser,10)
wait.until(EC.presence_of_element_located((By.ID,'content_left'))) #等到id爲content_left的元素加載完畢,最多等10秒
print(browser.page_source)
print(browser.current_url)
print(browser.get_cookies())
finally:
browser.close()
其它基本方法鏈接:https://www.cnblogs.com/jokerbj/p/8258902.html