selenium一些用法

基本使用方法

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

发布了17 篇原创文章 · 获赞 1 · 访问量 448

猜你喜欢

转载自blog.csdn.net/qq_36495121/article/details/100521720