滑动验证码-保存图片
https://www.sf-express.com/we/ow/chn/sc/waybill/list
# 保存图片
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import requests
headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36'}
def test1():
url = 'https://www.ssssssss.com/cn/sc/dynamic_function/waybill/#search/bill-number/SF1045585271138'
s = Service('./chromedriver.exe')
browser = webdriver.Chrome(service=s)
wait = WebDriverWait(browser,30)
browser.get(url)
try:
wait.until(EC.presence_of_element_located((By.ID,'tcaptcha_iframe')))
browser.switch_to.frame('tcaptcha_iframe')
img = browser.find_element(By.ID,'slideBg')
img_src = img.get_attribute('src')
img_src = img_src[:img_src.rfind('&')-1]
print(img_src)
save_img(f'{img_src}1','cpt1.png')
save_img(f'{img_src}2','cpt2.png')
browser.close()
except Exception as e:
browser.close()
def save_img(img,file_name):
resp = requests.get(f'{img}',headers =headers)
with open(f'./imgs/{file_name}','wb') as f:
f.write(resp.content)
if __name__ == '__main__':
test1()
标签:src,img,webdriver,selenium,验证码,保存,import,滑动,browser From: https://www.cnblogs.com/jiangjiayun/p/17538020.html