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()