dlxj commited on
Commit
f5ac12d
·
1 Parent(s): 15ece56

fix 第四十回下载失败

Browse files
Files changed (3) hide show
  1. ocr/getdata.py +14 -9
  2. ocr/readme.txt +3 -0
  3. ocr/requirements.txt +2 -3
ocr/getdata.py CHANGED
@@ -375,7 +375,7 @@ def _enter_image_mode(driver: webdriver.Chrome) -> None:
375
  def main() -> int:
376
  ap = argparse.ArgumentParser()
377
  ap.add_argument("--book-id", default="SWX0005")
378
- ap.add_argument("--chapter", default="第回")
379
  ap.add_argument("--out", default="out")
380
  ap.add_argument("--headless", action="store_true")
381
  ap.add_argument("--timeout", type=int, default=20000)
@@ -419,7 +419,7 @@ def main() -> int:
419
 
420
  clicked = False
421
  no_scroll_count = 0
422
- for scroll_attempts in range(200):
423
  try:
424
  els = driver.find_elements(By.LINK_TEXT, args.chapter)
425
  if not els:
@@ -430,12 +430,17 @@ def main() -> int:
430
 
431
  for el in els:
432
  try:
433
- if el.is_displayed() and el.is_enabled():
434
- driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", el)
435
- time.sleep(0.2)
436
  el.click()
437
  clicked = True
438
  break
 
 
 
 
 
439
  except Exception:
440
  continue
441
  except Exception:
@@ -453,7 +458,7 @@ def main() -> int:
453
  var d = els[i];
454
  if (d.scrollHeight > d.clientHeight && window.getComputedStyle(d).overflowY !== "hidden") {
455
  var before = d.scrollTop;
456
- d.scrollBy(0, 800);
457
  if (d.scrollTop > before) {
458
  scrolledAny = true;
459
  }
@@ -463,14 +468,14 @@ def main() -> int:
463
  ''')
464
  if not scrolled:
465
  no_scroll_count += 1
466
- if no_scroll_count >= 15:
467
- print(f"[DEBUG] Reached the bottom of the list (tried 15 times). {args.chapter} not found.")
468
  break
469
  else:
470
  no_scroll_count = 0
471
  except Exception:
472
  pass
473
- time.sleep(1.5)
474
 
475
  if clicked:
476
  print(f"[DEBUG] Clicked {args.chapter}, waiting for new network data...")
 
375
  def main() -> int:
376
  ap = argparse.ArgumentParser()
377
  ap.add_argument("--book-id", default="SWX0005")
378
+ ap.add_argument("--chapter", default="第十回")
379
  ap.add_argument("--out", default="out")
380
  ap.add_argument("--headless", action="store_true")
381
  ap.add_argument("--timeout", type=int, default=20000)
 
419
 
420
  clicked = False
421
  no_scroll_count = 0
422
+ for scroll_attempts in range(400):
423
  try:
424
  els = driver.find_elements(By.LINK_TEXT, args.chapter)
425
  if not els:
 
430
 
431
  for el in els:
432
  try:
433
+ driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", el)
434
+ time.sleep(0.2)
435
+ try:
436
  el.click()
437
  clicked = True
438
  break
439
+ except Exception:
440
+ # Try JS click as fallback if standard click fails
441
+ driver.execute_script("arguments[0].click();", el)
442
+ clicked = True
443
+ break
444
  except Exception:
445
  continue
446
  except Exception:
 
458
  var d = els[i];
459
  if (d.scrollHeight > d.clientHeight && window.getComputedStyle(d).overflowY !== "hidden") {
460
  var before = d.scrollTop;
461
+ d.scrollBy(0, 250);
462
  if (d.scrollTop > before) {
463
  scrolledAny = true;
464
  }
 
468
  ''')
469
  if not scrolled:
470
  no_scroll_count += 1
471
+ if no_scroll_count >= 20:
472
+ print(f"[DEBUG] Reached the bottom of the list (tried 20 times). {args.chapter} not found.")
473
  break
474
  else:
475
  no_scroll_count = 0
476
  except Exception:
477
  pass
478
+ time.sleep(0.5)
479
 
480
  if clicked:
481
  print(f"[DEBUG] Clicked {args.chapter}, waiting for new network data...")
ocr/readme.txt CHANGED
@@ -1,4 +1,7 @@
1
 
 
 
 
2
  python getdata.py
3
  先修改第几章,运行下载文本和坐标画框转换格式
4
 
 
1
 
2
+ Python 3.13.12
3
+
4
+
5
  python getdata.py
6
  先修改第几章,运行下载文本和坐标画框转换格式
7
 
ocr/requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
  requests
2
- OpenAI
3
- selenium
4
- numpy==1.23.5
5
  opencv-python==4.10.0.84
 
1
  requests
2
+ selenium==4.40.0
3
+ numpy<2.0.0
 
4
  opencv-python==4.10.0.84