from selenium import webdriver
from PIL import Image
import pytesseract
driver=webdriver.Firefox()
driver.get('网址')
driver.implicitly_wait(10)
for i in range(0,10):
driver.find_element_by_id('captchaImg').click()
driver.save_screenshot(r'E:\code_full.png')
href=driver.find_element_by_xpath('//*[@id="captchaImg"]')
left = href.location['x']
top = href.location['y']
elementWidth = href.location['x'] + href.size['width']
elementHeight = href.location['y'] + href.size['height']
picture = Image.open(r'E:\code_full.png')
picture = picture.crop((left, top, elementWidth, elementHeight))
picture.save(r'E:\\'+str(i)+'.png')
注意xpath和id,name需要根据自己要爬的网站结构进行编写