diff --git a/.gitignore b/.gitignore index 290b5b7..df82133 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.pyc screenshot.png result.png +screenshot.png diff --git a/main.py b/main.py index 516272e..76ac9ce 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ if __name__ == '__main__': options.add_argument('lang=zh-CN') options.add_argument( 'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36') - # options.add_argument(r'--user-data-dir=E:\Repository\skcks.cn\python-selenium-spider\tmp\UserData') + options.add_argument(r'--user-data-dir=E:\Repository\skcks.cn\python-selenium-spider\tmp\UserData') options.add_argument('--disable-gpu') # 如果不加这个选项,有时定位会出现问题 # options.add_argument('--headless') # 增加无界面选项 @@ -29,7 +29,7 @@ if __name__ == '__main__': "source": f.read() }) - run.run(driver=driver) + run.main(driver=driver) time.sleep(5) finally: driver.quit() \ No newline at end of file diff --git a/main_subprocess.py b/main_subprocess.py index c2101a0..0895275 100644 --- a/main_subprocess.py +++ b/main_subprocess.py @@ -20,7 +20,7 @@ if __name__ == '__main__': driver = webdriver.Chrome(options=chrome_options) try: - run.run(driver=driver) + run.main(driver=driver) time.sleep(5) finally: driver.close() diff --git a/run/__init__.py b/run/__init__.py index 1054a87..66a5744 100644 --- a/run/__init__.py +++ b/run/__init__.py @@ -6,10 +6,11 @@ from selenium.webdriver.remote.webdriver import WebDriver import utils -def run(driver:WebDriver): +def main(driver:WebDriver): driver.set_window_size(1920, 1080) - driver.get("https://bot.sannysoft.com/") + # driver.get("https://bot.sannysoft.com/")\ + driver.get("https://www.geetest.com/adaptive-captcha-demo") width = driver.execute_script("return document.documentElement.scrollWidth") height = driver.execute_script("return document.documentElement.scrollHeight") print(width, height) - utils.screenshot(driver=driver, save_path="./screenshot.png") \ No newline at end of file + utils.screenshot(driver=driver, save_path="./tmp/geetest.png") \ No newline at end of file diff --git a/screenshot.png b/screenshot.png index 5927928..1fc71cc 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/utils/__init__.py b/utils/__init__.py index 2956810..c27fc10 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -12,7 +12,7 @@ def screenshot(driver:WebDriver, save_path): file_name = os.path.basename(save_path) if not os.path.exists(_tmp_dir): os.mkdir(_tmp_dir) - + tmp_file_list = [] try: tmp_file = _tmp_file % (file_name, 0) @@ -22,7 +22,7 @@ def screenshot(driver:WebDriver, save_path): current_h = driver.execute_script("return document.documentElement.clientHeight") for i in range(1, int(body_h / current_h)): driver.execute_script(_scroll_to_y % (current_h * i)) - time.sleep(0.2) + time.sleep(0.5) driver.save_screenshot(_tmp_file % (file_name, i)) tmp_file_list.append(_tmp_file % (file_name, i)) merge_images(tmp_file, _tmp_file % (file_name, i), tmp_file) @@ -36,10 +36,10 @@ def screenshot(driver:WebDriver, save_path): # 删除临时文件 for tmp in tmp_file_list: os.remove(tmp) - + def merge_images(image1: str, image2: str,output: str,overlap_size=0): - size = overlap_size * 2 + size = overlap_size img1,img2 = Image.open(image1), Image.open(image2) size1, size2 = img1.size, img2.size merge = Image.new("RGB", (size1[0], size1[1] + size2[1] - size))