当前位置:网站首页>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
边栏推荐
- ES6
- Detailed deployment of flask project
- This point in JS
- Client example analysis of easymodbustcp
- Hcip fifth experiment
- Summary of floating point double precision, single precision and half precision knowledge
- 2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
- C network related operations
- 极致体验,揭晓抖音背后的音视频技术
- Notes on common basic usage of eigen Library
猜你喜欢
SystemVerilog(六)-变量
Flask项目的部署详解
YOLOv4剪枝【附代码】
QTableWidget使用讲解
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
The ultimate experience, the audio and video technology behind the tiktok
Nat commun | current progress and open challenges of applied deep learning in Bioscience
1217_ Generating target files using scons
In JS, t, = > Analysis of
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
随机推荐
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
k8s之实现redis一主多从动态扩缩容
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
1217_ Generating target files using scons
Go对文件操作
.104History
开源按键组件Multi_Button的使用,含测试工程
Classes and objects
土地覆盖/利用数据产品下载
Encapsulate a timestamp to date method on string prototype
.104History
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
MySQL advanced index [classification, performance analysis, use, design principles]
JS forms the items with the same name in the array object into the same array according to the name
_ FindText error
Build openstack platform
.105Location
Write a regular
MySQL_01_简单数据检索