Commit 4060af6c authored by huangziyu's avatar huangziyu

1

parent 446cd288
...@@ -31,6 +31,7 @@ mysql_zdzs_proxy_user = 'zgcindex' ...@@ -31,6 +31,7 @@ mysql_zdzs_proxy_user = 'zgcindex'
mysql_zdzs_proxy_password = 'zgcprice2019' mysql_zdzs_proxy_password = 'zgcprice2019'
mysql_zdzs_proxy_database = 'zdzs_proxy' mysql_zdzs_proxy_database = 'zdzs_proxy'
import config import config
username = config.username username = config.username
# 登陆密码 # 登陆密码
password = config.password password = config.password
...@@ -188,14 +189,19 @@ def detect_circular_distortion(image_path, circle_radius=65): ...@@ -188,14 +189,19 @@ def detect_circular_distortion(image_path, circle_radius=65):
return average_distance return average_distance
def any_of_elements_present(*locators): def any_of_elements_present(*locators):
"""检查给定的任意一个元素是否出现在DOM中""" """检查给定的任意一个元素是否出现在DOM中"""
def _predicate(driver): def _predicate(driver):
for locator in locators: for locator in locators:
if EC.presence_of_element_located(locator)(driver): if EC.presence_of_element_located(locator)(driver):
return True return True
return False return False
return _predicate return _predicate
def find_best_match_angle(background_img_path, rotating_img_path): def find_best_match_angle(background_img_path, rotating_img_path):
# 加载背景图片和验证码图片 # 加载背景图片和验证码图片
background = Image.open(background_img_path) background = Image.open(background_img_path)
...@@ -340,8 +346,8 @@ def get_cookie(): ...@@ -340,8 +346,8 @@ def get_cookie():
element = driver.find_element_by_class_name("JDJRV-slide-btn") element = driver.find_element_by_class_name("JDJRV-slide-btn")
# 获取元素的X和Y位置 # 获取元素的X和Y位置
x_position = element.location['x']+50 x_position = element.location['x'] + 50
y_position = element.location['y']+100 y_position = element.location['y'] + 100
print("元素的X位置:", x_position) print("元素的X位置:", x_position)
print("元素的Y位置:", y_position) print("元素的Y位置:", y_position)
...@@ -393,7 +399,8 @@ def get_cookie(): ...@@ -393,7 +399,8 @@ def get_cookie():
print("网页加载完成") print("网页加载完成")
text = driver.page_source text = driver.page_source
while_count = 0 while_count = 0
while ('快速验证' in text and '验证一下,购物无忧' in text) or '前方拥挤,请刷新重试' in text or 'class="title">加载中...</span></div></div><!----></div>' in text: while (
'快速验证' in text and '验证一下,购物无忧' in text) or '前方拥挤,请刷新重试' in text or 'class="title">加载中...</span></div></div><!----></div>' in text:
while_count += 1 while_count += 1
if while_count > 1: if while_count > 1:
driver.get(url) driver.get(url)
...@@ -439,8 +446,8 @@ def get_cookie(): ...@@ -439,8 +446,8 @@ def get_cookie():
element = driver.find_element_by_class_name("bg-blue") element = driver.find_element_by_class_name("bg-blue")
# 获取元素的X和Y位置 # 获取元素的X和Y位置
x_position = element.location['x']+50 x_position = element.location['x'] + 50
y_position = element.location['y']+100 y_position = element.location['y'] + 100
print("元素的X位置:", x_position) print("元素的X位置:", x_position)
print("元素的Y位置:", y_position) print("元素的Y位置:", y_position)
...@@ -473,6 +480,9 @@ def get_cookie(): ...@@ -473,6 +480,9 @@ def get_cookie():
except NoSuchElementException: except NoSuchElementException:
# print("未查找到验证图片背景图,可能是旋转图片,换一种方式获取div") # print("未查找到验证图片背景图,可能是旋转图片,换一种方式获取div")
try: try:
while_count_2 = 0
while while_count_2 < 5:
while_count_2 += 1
background = driver.find_element(by=By.XPATH, value='//*[@id="img-back-div"]') background = driver.find_element(by=By.XPATH, value='//*[@id="img-back-div"]')
background_url = background.get_attribute("style").replace('"); height: 181px;', "").replace( background_url = background.get_attribute("style").replace('"); height: 181px;', "").replace(
'background-image: url("', "") 'background-image: url("', "")
...@@ -499,8 +509,8 @@ def get_cookie(): ...@@ -499,8 +509,8 @@ def get_cookie():
element = driver.find_element_by_id("slider-div") element = driver.find_element_by_id("slider-div")
# 获取元素的X和Y位置 # 获取元素的X和Y位置
x_position = element.location['x']+50 x_position = element.location['x'] + 50
y_position = element.location['y']+100 y_position = element.location['y'] + 100
print("元素的X位置:", x_position) print("元素的X位置:", x_position)
print("元素的Y位置:", y_position) print("元素的Y位置:", y_position)
...@@ -508,14 +518,14 @@ def get_cookie(): ...@@ -508,14 +518,14 @@ def get_cookie():
# time.sleep(0.5) # time.sleep(0.5)
SlideUtils.slide_by_pyautogui2(x_position, SlideUtils.slide_by_pyautogui2(x_position,
y_position, y_position,
x+2, x + 2,
offset_increase) offset_increase)
try: try:
WebDriverWait(driver, 2).until( WebDriverWait(driver, 2).until(
EC.presence_of_element_located((By.ID, "J_main")) EC.presence_of_element_located((By.ID, "J_main"))
) )
text = driver.page_source text = driver.page_source
continue break
except: except:
try: try:
WebDriverWait(driver, 5).until( WebDriverWait(driver, 5).until(
...@@ -524,7 +534,7 @@ def get_cookie(): ...@@ -524,7 +534,7 @@ def get_cookie():
except NoSuchElementException: except NoSuchElementException:
print("网页加载异常") print("网页加载异常")
text = driver.page_source text = driver.page_source
continue break
finally: finally:
print("网页加载完成") print("网页加载完成")
finally: finally:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment