Browse Source

1、添加滑动页面特征检测 2、添加代理Ip验证通过检测

dongzhaorui 2 years ago
parent
commit
1b44186d5c
1 changed files with 11 additions and 9 deletions
  1. 11 9
      zgztb_cookie/cookie_pool.py

+ 11 - 9
zgztb_cookie/cookie_pool.py

@@ -29,8 +29,8 @@ class WebCookiePool(PageCookiePool):
                 print(' window.navigator.webdriver >>> ', result)
                 driver.get(self.page_url)
                 time.sleep(3)
-
-                for i in range(4):
+                for _ in range(4):
+                    log.info(f"【{driver.title}】,处理中...")
                     try:
                         slider = driver.find_element_by_xpath("//span[contains(@class, 'nc_iconfont btn_slide')]")
                         if slider.is_displayed():
@@ -42,19 +42,20 @@ class WebCookiePool(PageCookiePool):
                             ActionChains(driver).pause(1).release().perform()
                     except NoSuchElementException:
                         if '找不到 输入的jsp页面或者服务器' == driver.title:
+                            # 切换新ip,不触发阿里人机验证,浏览器信息缺少acw3,需要再次发起请求
                             break
                     except Exception as e:
                         reason = 'nsIDOMWindowUtils.sendMouseEvent'
                         if len(e.args) > 0 and e.args[0].count(reason) == 0:
-                            # 是否频繁访问,导致代理ip被封
                             if driver.title == '出错了':
+                                # 代理ip频繁访问,导致被封,直接切换代理
                                 break
 
                             log.error(f"异常原因:{e.args}")
 
-                    time.sleep(10)
+                    time.sleep(10)  # ip数量少,间隔时间放大一些
 
-                    # 检查代理ip是否通过验证
+                    # 滑动页面特征
                     try:
                         feature = driver.find_element_by_xpath('//body').text
                     except NoSuchElementException:
@@ -62,14 +63,15 @@ class WebCookiePool(PageCookiePool):
 
                     if 'IP地址在短时间内频繁访问该页面' in feature:
                         return
-
-                    # 检查页面是否存在无感滑块元素
-                    if 'nc_iconfont btn_slide' in driver.page_source:
+                    elif '访问被阻断' in feature:
+                        return
+                    elif 'nc_iconfont btn_slide' in driver.page_source:
+                        # 检查页面是否存在滑块元素
                         continue
                     else:
                         break
+                log.info(f"【{driver.title}】,处理结束")
                 return driver.cookies
-
             except Exception as e:
                 log.error(f"cookie获取失败:{e}")