因为抓取b站部分信息需要登陆,所以最好使用单独的登陆逻辑获取coockie并放入cookie池内解决数据抓取问题。 这个项目就是用来登陆b站用的
b站登陆的时候使用了滑动验证码,该项目可以破解滑动验证码并且成功登陆b站,登陆成功后便可以获取的cookie然后进行更进一步的抓取。
selenium
,ActionChains
,PIL
使用browser执行js脚本,修改元素的style
browser.execute_script('document.querySelectorAll("canvas")[3].style=""')
对比两个像素的RGB值,判断是否相同,用于找到缺口位置
def compare_pixel(self,image1,image2,x,y):
#判断两个像素是否相同
pixel1 = image1.load()[x,y]
pixel2 = image2.load()[x,y]
threshold = 60
if abs(pixel1[0]-pixel2[0]) < threshold and abs(pixel1[1]-pixel2[1]) < threshold and abs(pixel1[2]-pixel2[2]) < threshold:
return True
else:
return False
使用 PIL中的 Image函数打开图片,遍历像素,并且当两个像素不同的时候返回当前像素坐标。
def compare(self):
capture1 = Image.open('./before.png')
capture2 = Image.open('./after.png')
#获取缺口位置
left = 60
has_find = False
for i in range(60,capture1.size[0]):
if has_find:
break
for j in range(capture1.size[1]):
if not self.compare_pixel(capture1,capture2,i,j):
left = i
has_find = True
break
left -= 6
return left