from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver import ActionChains from PIL import Image import time import pygame # 汉字转化成图片 def chinese_to_img(text): pygame.init() # text = u"文字转图片" font = pygame.font.SysFont('simhei', 16) ftext = font.render(text, True, (65, 83, 130), (255, 255, 255)) pygame.image.save(ftext, "image.png") # 图片保存地址 driver=webdriver.Chrome() driver.get("https://www.qichacha.com/user_login") driver.find_element_by_id("normalLogin").click() driver.find_element_by_id("nameNormal").send_keys("17320180454") driver.find_element_by_id("pwdNormal").send_keys("17320180454") # 移动鼠标 time.sleep(1) move_k=driver.find_element_by_id("nc_1_n1z") ActionChains(driver).drag_and_drop_by_offset(move_k,341,0).perform() time.sleep(2) # 截取图片 driver.save_screenshot('bdbutton.png') element = driver.find_element_by_xpath('//*[@id="nc_1_clickCaptcha"]/div[2]/img') print(element.location) # 打印元素坐标 print(element.size) # 打印元素大小 left = element.location['x'] top = element.location['y'] right = element.location['x'] + element.size['width'] bottom = element.location['y'] + element.size['height'] im = Image.open('bdbutton.png') im = im.crop((left, top, right, bottom)) im.save('bdbutton.png') text=driver.find_element_by_xpath('//*[@id="nc_1__scale_text"]').text chinese_to_img(text) # 合并图片 import win32print import win32ui import win32con from PIL import Image, ImageDraw, ImageFont, ImageWin, ImageColor import os def merge(image1, image2): ''' 实现垂直合并两张图片 @param image1: 需要合并的第一张图片 @param image2: 需要合并的第二张图片 ''' w1, h1 = image1.size w2, h2 = image2.size target = Image.new('RGB', (w1 if w1 > w2 else w2 , h1 + h2), (255, 255, 255, 0)) temp = image1.resize((w1, h1), Image.ANTIALIAS) target.paste(temp, (0, 0, w1, h1)) temp1 = image2.resize((w2, h2), Image.ANTIALIAS) target.paste(temp1, (0, h1, w2, h1 + h2)) target.save('merge.png') if __name__ == '__main__': printer_name = win32print.GetDefaultPrinter() print(printer_name) merge(Image.open('image.png'), Image.open('bdbutton.png')) if os.path.exists("merge.png"): import chaojiyings chaojiying = chaojiyings.Chaojiying_Client('1234567890', '1234567890', '96001') # 用户中心>>软件ID 生成一个替换 96001 im = open('merge.png', 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要// # print(chaojiying.PostPic(im, 9101)) move_m = driver.find_element_by_xpath('//*[@id="nc_1_clickCaptcha"]/div[2]/img') ActionChains(driver).drag_and_drop_by_offset(move_m, 20, 40).click().perform()
企查查登录验证(selenium)
猜你喜欢
转载自www.cnblogs.com/gaoyukun/p/9714671.html
今日推荐
周排行