这个网址的图片无法保存
https://trade.,这是一张验证码图片地址,因为request无法识别这个网站的内容。因此无法保存到本地。请教各位大神,应如何将此网址对应图片保存到本地,谢谢!
from selenium import webdriver from selenium. import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time import os from PIL import Image def Element2text(driver,element):#传入driver,和验证码所在element,返回字符串 #print('Element2text(1)') temp = "" try: Photo_time = time.strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))#time库不支持%f毫秒 #print('Element2text(2)') Photo_url = os.getcwd()+"\\"+Photo_time+'.png' time.sleep(0.6)#确保每轮截图能间隔一秒 driver.get_screenshot_as_file(Photo_url) except BaseException as msg: print(msg) return temp try: #print('Element2text(3)') left = element.location['x'] + 5 #获取验证码最左边位置 top = element.location['y'] #获取验证码最上边位置 right = left + element.size['width'] #获取验证码最右边位置 bottom = top + element.size['height'] #获取验证码最下边位置 except BaseException as msg: print(msg) print('问询验证码坐标信息失败') return temp try: print(Photo_url) Open_img = Image.open(Photo_url) Open_img = Open_img.crop((left,top,right,bottom))#剪切图片 Open_img.save(Photo_url)#将剪切后的图片保存回原位置 #print('Element2text(5)') temp = image2text(Photo_url) os.rename(Photo_url,os.getcwd()+"\\"+Photo_time+"["+temp+"].png") except BaseException as msg: print(msg) print('修建截图出现未知错误') return temp