当前位置:网站首页>Selenium + phantom JS crack sliding verification 2
Selenium + phantom JS crack sliding verification 2
2022-04-23 17:58:00 【Feng Ye 520】
from selenium import webdriver
from PIL import Image
from io import BytesIO
import re
import requests
import numpy as np
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from random import randint
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
)
class Bilibili:
def __init__(self):
self.broswer = webdriver.PhantomJS(executable_path=r'C:\phantomjs-2.1.1-windows\bin\phantomjs.exe',
desired_capabilities=dcap)
self.broswer.set_page_load_timeout(20)
self.broswer.implicitly_wait(10)
def get_page(self):
self.broswer.get('https://passport.bilibili.com/login')
name = self.broswer.find_element_by_id('login-username')
name.send_keys('usename')
passwd = self.broswer.find_element_by_id('login-passwd')
passwd.send_keys('passwd')
def get_img(self):
# pattern = re.compile(r'background-image: url\(\"([^\']+)\"\); background-position: ([^p]+)px ([^p]+)px;')
pattern = re.compile(r'background-image: url\(([^\']+)\); background-position: ([^p]+)px ([^p]+)px;')
img1 = self.broswer.find_element_by_class_name('gt_cut_bg_slice').get_attribute('style')
img2 = self.broswer.find_element_by_class_name('gt_cut_fullbg_slice').get_attribute('style')
img1_url = pattern.findall(img1)[0][0]
img2_url = pattern.findall(img2)[0][0]
img1_url = img1_url.replace('webp','jpg')
img2_url = img2_url.replace('webp','jpg')
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"}
request_img1 = requests.get(img1_url,headers = headers).content
img1_content = Image.open(BytesIO(request_img1))
request_img2 = requests.get(img2_url,headers = headers).content
img2_content = Image.open(BytesIO(request_img2))
return img1_content,img2_content
def crop_img(self):
img1_content,img2_content = self.get_img()
# pattern = re.compile(r'background-image: url\(\"([^\']+)\"\); background-position: ([^p]+)px ([^p]+)px;')
pattern = re.compile(r'background-image: url\(([^\']+)\); background-position: ([^p]+)px ([^p]+)px;')
imgs1 = self.broswer.find_elements_by_class_name('gt_cut_bg_slice')
imgs2 = self.broswer.find_elements_by_class_name('gt_cut_fullbg_slice')
img1_coord_list = []
img2_coord_list = []
for img1 in imgs1:
img1_x = int(pattern.findall(img1.get_attribute('style'))[0][1])
img1_y = int(pattern.findall(img1.get_attribute('style'))[0][2])
img1_coord_list.append([img1_x,img1_y])
for img2 in imgs2:
img2_x = int(pattern.findall(img2.get_attribute('style'))[0][1])
img2_y = int(pattern.findall(img2.get_attribute('style'))[0][2])
img2_coord_list.append([img2_x,img2_y])
new_img1 = Image.new('RGB',(260,116))
new_img2 = Image.new('RGB',(260,116))
offset_x_down = 0
offset_x_upper = 0
for img1_x,img1_y in img1_coord_list:
if img1_y == -58:
img1_crop = img1_content.crop((abs(img1_x),58,abs(img1_x)+10,116))
new_img1.paste(img1_crop,(offset_x_upper,0))
offset_x_upper+=10
elif img1_y == 0:
img1_crop = img1_content.crop((abs(img1_x),0,abs(img1_x)+10,58))
new_img1.paste(img1_crop,(offset_x_down,58))
offset_x_down+=10
offset_x_down = 0
offset_x_upper = 0
for img2_x,img2_y in img2_coord_list:
if img2_y == -58:
img2_crop = img2_content.crop((abs(img2_x),58,abs(img2_x)+10,116))
new_img2.paste(img2_crop,(offset_x_upper,0))
offset_x_upper+=10
elif img2_y == 0:
img2_crop = img2_content.crop((abs(img2_x),0,abs(img2_x)+10,58))
new_img2.paste(img2_crop,(offset_x_down,58))
offset_x_down+=10
return new_img1,new_img2
def diff_img(self):
new_img1,new_img2 = self.crop_img()
for x in range(new_img1.size[0]):
for y in range(new_img1.size[1]):
px1 = new_img1.getpixel((x, y))
px2 = new_img2.getpixel((x, y))
for i in range(3):
if abs(px1[i]-px2[i])>=50:
return x, y
def track(self):
length = self.diff_img()[0]-6
length_1 = int(length*0.7)
length_2 = length-length_1
button = self.broswer.find_element_by_xpath('//*[@id="gc-box"]/div/div[3]/div[2]')
ActionChains(self.broswer).click_and_hold(on_element=button).perform()
for i in range(length_1):
ActionChains(self.broswer).move_by_offset(1,0).perform()
sleep(randint(0,20)/1000)
for i in range(length_2):
ActionChains(self.broswer).move_by_offset(1,0).perform()
sleep(randint(30,50)/1000)
ActionChains(self.broswer).release(on_element=button).perform()
sleep(2)
result = self.broswer.find_element_by_class_name('gt_info_type')
# print(result.text)
return result.text
def action(self):
self.get_page()
while True:
result = self.track()
if u' Again ' in result:
print(result)
sleep(4)
continue
elif u' adopt ' in result:
print(result)
break
elif u' Failure ' in result:
self.broswer.execute_script('location.reload()')
print(' Refresh the page ')
sleep(4)
else:
print(result)
break
b = Bilibili()
b.action()
版权声明
本文为[Feng Ye 520]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230546134259.html
边栏推荐
- Data stream encryption and decryption of C
- 2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
- MySQL_ 01_ Simple data retrieval
- 开源按键组件Multi_Button的使用,含测试工程
- Eigen learning summary
- Leak detection and vacancy filling (VIII)
- Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
- Leak detection and vacancy filling (6)
- Oil monkey website address
- 列錶的使用-增删改查
猜你喜欢
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
Tell the truth of TS
C1 notes [task training chapter I]
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
开源按键组件Multi_Button的使用,含测试工程
The ultimate experience, the audio and video technology behind the tiktok
Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
Summary of floating point double precision, single precision and half precision knowledge
2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
Implementation of k8s redis one master multi slave dynamic capacity expansion
随机推荐
Halo open source project learning (II): entity classes and data tables
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
列表的使用-增删改查
高德地图搜索、拖拽 查询地址
Hcip fifth experiment
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
ES6 face test questions (reference documents)
C network related operations
Go的Gin框架学习
Halo 开源项目学习(二):实体类与数据表
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Cross domain settings of Chrome browser -- including new and old versions
vite配置proxy代理解决跨域
ES6 new method
2022年上海市安全员C证操作证考试题库及模拟考试
Nanotechnology + AI enabled proteomics | Luomi life technology completed nearly ten million US dollars of financing
Transfer learning of five categories of pictures based on VGg
Error in created hook: "referenceerror:" promise "undefined“
C language loop structure program