import random
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from urllib.request import urlretrieve
from selenium import webdriver
from bs4 import BeautifulSoup
import PIL.Image as image
import re
class Crack():
def __init__(self, username, passwd):
self.url = 'https://passport.bilibili.com/login'
self.browser = webdriver.Chrome()
self.wait = WebDriverWait(self.browser, 100)
self.BORDER = 6
self.passwd = passwd
self.username = username
def open(self):
"""
打开浏览器,并输入查询内容
"""
self.browser.get(self.url)
keyword = self.wait.until(EC.presence_of_element_located((By.ID, 'login-username')))
keyword.send_keys(self.username)
keyword = self.wait.until(EC.presence_of_element_located((By.ID, 'login-passwd')))
keyword.send_keys(self.passwd)
# bowton.click()
def get_images(self, bg_filename='bg.jpg', fullbg_filename='fullbg.jpg'):
"""
获取验证码图片
:return: 图片的location信息
"""
bg = []
fullgb = []
while bg == [] and fullgb == []:
bf = BeautifulSoup(self.browser.page_source, 'lxml')
bg = bf.find_all('div', class_='gt_cut_bg_slice')
fullgb = bf.find_all('div', class