python + selenium 保存二维码(以百度网盘登陆二维码为例)


import wx
import time
import os
from selenium import webdriver

#########selenium 基本设置###############################################################
#百度网盘首页
url_cs = 'https://pan.baidu.com/'
path='chromedriver.exe'  #chromedriver地址
conceal = 0 #为1是隐藏浏览器
if conceal == 1:
#隐藏浏览器
    chrome_opts=webdriver.ChromeOptions()
    chrome_opts.add_argument("--headless")
    Chrome=webdriver.Chrome(path,chrome_options=chrome_opts)
else:
    #不隐藏浏览器
    Chrome=webdriver.Chrome(path)
Chrome.maximize_window()   #浏览器最大化,便于截图

##########selenium 请求页面##############################################################
#进入网盘页面首页
time1 =time.time()
Chrome.get(url_cs)
time.sleep(5) #等待网页完全刷新完成
Chrome.find_element_by_id('TANGRAM__PSP_4__footerQrcodeBtn').click()

#######截图二维码及处理打开(主要)#########################################################
img_path = './二维码.png'
Chrome.save_screenshot(img_path) # 一次截图:形成全图
QR = Chrome.find_element_by_class_name('tang-pass-qrcode-img') #定位二维码位置
left = QR.location['x']  # 区块截图左上角在网页中的x坐标
top = QR.location['y']  # 区块截图左上角在网页中的y坐标
right = left + QR.size['width']  # 区块截图右下角在网页中的x坐标
bottom = top + QR.size['height']  # 区块截图右下角在网页中的y坐标
from PIL import Image
picture = Image.open(img_path)
picture = picture.crop((left, top, right, bottom))  # 二次截图:形成区块截图
picture.save(img_path)
print("--已下载完成二维码")
img=Image.open(img_path)
img.show()
time.sleep(25) #等待二维码扫描时间
# Chrome.quit()

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值