selenium模块
一、基础知识
1 基础
official::Selenium 浏览器自动化项目 | Selenium
API:键鼠操作
驱动下载:
等待
2 使用驱动
from selenium.webdriver.chrome.service import Service ser = Service(r"./chromedriver.exe") bro = webdriver.Chrome(service = ser)
|
3 简单使用
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(" ")
text = driver.page_source
from selenium.webdriver.common.by import By
input_tag = driver.find_element(by,value)
input_tag.send_keys()
from selenium.webdriver.common.keys import Keys
send_keys( Keys.ENTER )
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).click(input_tag).perform()
input_tag.click()
driver.back()
driver.forward()
driver.quit()
|
4 定位
iframe:driver.switch_to.frame('id')
ActionChains(bro).move_to_element_with_offset(tag,x,y).click().perform()
|
5 其他设置
from selenium.webdriver.chrome.options import Options
op = Options() op.add_argument('--headless') op.add_argument('--disable-gpu') driver = webdriver.Chrome(options=op)
op = Options() op.add_experimental_option('excludeSwitches',['enable-automation']) driver = webdriver.Chrome(options=op)
|
6 鼠标高级操作
action = ActionChains(driver) action.click_and_hold(tag) for i in range(num) : action.move_by_offset(x,y).perform() action.release()
|
7 其他操作
driver.save_screenshot(".png")
tag.location
tag.size:
|
二、 图片处理
1 使用Image
from PIL import Image
im = Image.open(path)
res = im.crop(tuple)
res.save(path)
|