#!/usr/bin/env python
# encoding: utf-8
# @author: jack
# @contact: 935650354@qq.com
# @site: https://www.cnblogs.com/jackzz
import re
import time
import random
import requests
import selenium
from PIL import Image
from seleniumwire import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from io import BytesIO
from selenium.webdriver.common.action_chains import ActionChains
from browsermobproxy import Server
def main(driver, element, x):
# 1为完整图、2为有缺口图
# image1 = get_img(driver, 'oriImg', 1)
# image2 = get_img(driver, 'cutImg', 2)
#
# x = get_diff_location(image1, image2)
tracks = get_track(x)
time.sleep(0.5)
ActionChains(driver).click_and_hold(element).perform()
# for x in tracks:
ActionChains(driver).move_by_offset(xoffset=x, yoffset=0).perform()
ActionChains(driver).release(element).perform()
# time.sleep(0.5)
if __name__ == '__main__':
driver = webdriver.Chrome(executable_path=r"C:\Users\Administrator\PycharmProjects\chinaSpider\chromedriver.exe")
driver.maximize_window()
driver.get('*********************************')
inputLabel = driver.find_element_by_class_name("search_input");
inputLabel.send_keys("协会")
searchButton = driver.find_element_by_class_name("search_button")
searchButton.click()
antModel = driver.find_element_by_class_name("ant-modal")
if antModel:
# noinspection PyBroadException
try:
x = 150
count = 100
# waiting slidingVC loading
wait = WebDriverWait(driver, 2)
try:
element = wait.until(EC.invisibility_of_element((By.CLASS_NAME, 'slider')))
except Exception:
choseBtn = driver.find_element_by_class_name('ant-modal-close')
choseBtn.click()
time.sleep(2)
searchButton.click()
element = wait.until(EC.invisibility_of_element((By.CLASS_NAME, 'slider')))
while count > 0:
switch = 0
if x > 250:
x = 152
try:
driver.find_element_by_class_name("slider_success")
switch = 1
except selenium.common.exceptions.NoSuchElementException:
switch = 0
if switch == 1:
refreshButton = driver.find_element_by_xpath('//*[@id="captchaContainer"]/div[1]/img')
refreshButton.click()
time.sleep(1)
main(driver, element, x)
try:
succes = wait.until(
EC.presence_of_element_located((By.XPATH, '//div[@class="search_title"]')))
if succes:
# Access requests via the `requests` attribute
print(driver.requests[len(driver.requests)-2].params)
# for request in driver.requests:
# print(request.params)
print('恭喜你!识别成功...')
break
except Exception as e:
print('识别错误,继续,' + "滑动距离为:%d" % x)
count -= 1
x += 8
finally:
driver.quit()
else:
print("NOCAPTCHE")
python selinium-wire破解滑动验证码获取请求头
最新推荐文章于 2024-07-29 17:24:13 发布
本文介绍了一段Python脚本,通过Selenium和BrowserMobProxy实现网站搜索过程中的滑动验证码识别。作者展示了如何定位元素并模拟滑动操作,核心内容包括图像处理、坐标跟踪和webdriver操作。
摘要由CSDN通过智能技术生成