bobocup commited on
Commit
2874565
·
verified ·
1 Parent(s): a8fa438

Update nb4x.py

Browse files
Files changed (1) hide show
  1. nb4x.py +59 -10
nb4x.py CHANGED
@@ -125,18 +125,60 @@ def wait_for_email_input(driver, timeout=10):
125
  start_time = time.time()
126
  while time.time() - start_time < timeout:
127
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  input_js = """
129
- return document.querySelector("#AppProvider_Wrapper > form > descope-wc")
130
- .shadowRoot.querySelector("#TExZpnv5m6")
131
- .shadowRoot.querySelector("#input-vaadin-email-field-3")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  """
133
- email_input = driver.execute_script(input_js)
134
- if email_input:
 
 
135
  logger.info("邮箱输入框已加载")
136
  return True
137
- except Exception:
138
- pass
 
 
 
139
  time.sleep(0.5)
 
140
  logger.error("邮箱输入框未出现")
141
  return False
142
 
@@ -240,13 +282,20 @@ def registration_process(driver, wait):
240
  return False
241
 
242
  def single_registration():
243
- # 创建Chrome选项
244
  chrome_options = Options()
245
  chrome_options.add_argument('--no-sandbox')
246
  chrome_options.add_argument('--disable-dev-shm-usage')
247
  chrome_options.add_argument('--disable-gpu')
248
  chrome_options.add_argument('--headless=new')
249
 
 
 
 
 
 
 
 
 
250
  # 其他优化选项
251
  chrome_options.add_argument('--disable-blink-features=AutomationControlled')
252
  chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
@@ -284,10 +333,10 @@ def worker(thread_id):
284
  logger.info(f"线程 {thread_id}: 本次循环成功")
285
  else:
286
  error_count += 1
287
- logger.error(f"线程 {thread_id}: 本次循环失败,这第 {error_count} 次失败")
288
 
289
  if error_count >= 5:
290
- logger.critical(f"线程 {thread_id}: 续 {error_count} 次失败,退出线程")
291
  break
292
 
293
  if not success:
 
125
  start_time = time.time()
126
  while time.time() - start_time < timeout:
127
  try:
128
+ # 获取页面标题
129
+ logger.info(f"当前页面标题: {driver.title}")
130
+
131
+ # 检查页面源代码中是否包含关键元素
132
+ logger.info("检查页面源代码...")
133
+ if "descope-wc" in driver.page_source:
134
+ logger.info("找到 descope-wc 元素")
135
+ else:
136
+ logger.info("未找到 descope-wc 元素")
137
+
138
+ # 尝试获取 Shadow DOM 元素
139
+ try:
140
+ wrapper = driver.find_element(By.CSS_SELECTOR, "#AppProvider_Wrapper > form > descope-wc")
141
+ logger.info("找到 wrapper 元素")
142
+ except:
143
+ logger.info("未找到 wrapper 元素")
144
+
145
+ # 原来的元素查找逻辑
146
  input_js = """
147
+ var wrapper = document.querySelector("#AppProvider_Wrapper > form > descope-wc");
148
+ if (!wrapper) {
149
+ return "wrapper not found";
150
+ }
151
+ var shadow1 = wrapper.shadowRoot;
152
+ if (!shadow1) {
153
+ return "shadow1 not found";
154
+ }
155
+ var elem = shadow1.querySelector("#TExZpnv5m6");
156
+ if (!elem) {
157
+ return "elem not found";
158
+ }
159
+ var shadow2 = elem.shadowRoot;
160
+ if (!shadow2) {
161
+ return "shadow2 not found";
162
+ }
163
+ var input = shadow2.querySelector("#input-vaadin-email-field-3");
164
+ if (!input) {
165
+ return "input not found";
166
+ }
167
+ return "found";
168
  """
169
+ result = driver.execute_script(input_js)
170
+ logger.info(f"元素查找结果: {result}")
171
+
172
+ if result == "found":
173
  logger.info("邮箱输入框已加载")
174
  return True
175
+
176
+ except Exception as e:
177
+ logger.error(f"查找元素时发生错误: {str(e)}")
178
+
179
+ logger.info("等待0.5秒后重试...")
180
  time.sleep(0.5)
181
+
182
  logger.error("邮箱输入框未出现")
183
  return False
184
 
 
282
  return False
283
 
284
  def single_registration():
 
285
  chrome_options = Options()
286
  chrome_options.add_argument('--no-sandbox')
287
  chrome_options.add_argument('--disable-dev-shm-usage')
288
  chrome_options.add_argument('--disable-gpu')
289
  chrome_options.add_argument('--headless=new')
290
 
291
+ # 添加更多日志
292
+ chrome_options.add_argument('--enable-logging')
293
+ chrome_options.add_argument('--v=1')
294
+
295
+ # 确保 JavaScript 正常运行
296
+ chrome_options.add_argument('--enable-javascript')
297
+ chrome_options.add_argument('--disable-web-security')
298
+
299
  # 其他优化选项
300
  chrome_options.add_argument('--disable-blink-features=AutomationControlled')
301
  chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
 
333
  logger.info(f"线程 {thread_id}: 本次循环成功")
334
  else:
335
  error_count += 1
336
+ logger.error(f"线程 {thread_id}: 本次循环失败,这���第 {error_count} 次失败")
337
 
338
  if error_count >= 5:
339
+ logger.critical(f"线程 {thread_id}: 续 {error_count} 次失败,出线程")
340
  break
341
 
342
  if not success: