调整截图问题
This commit is contained in:
parent
f2fc675d51
commit
05532dd278
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
screenshot.png
|
screenshot.png
|
||||||
result.png
|
result.png
|
||||||
|
screenshot.png
|
||||||
|
4
main.py
4
main.py
@ -8,7 +8,7 @@ if __name__ == '__main__':
|
|||||||
options.add_argument('lang=zh-CN')
|
options.add_argument('lang=zh-CN')
|
||||||
options.add_argument(
|
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')
|
'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('--disable-gpu') # 如果不加这个选项,有时定位会出现问题
|
||||||
# options.add_argument('--headless') # 增加无界面选项
|
# options.add_argument('--headless') # 增加无界面选项
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ if __name__ == '__main__':
|
|||||||
"source": f.read()
|
"source": f.read()
|
||||||
})
|
})
|
||||||
|
|
||||||
run.run(driver=driver)
|
run.main(driver=driver)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
finally:
|
finally:
|
||||||
driver.quit()
|
driver.quit()
|
@ -20,7 +20,7 @@ if __name__ == '__main__':
|
|||||||
driver = webdriver.Chrome(options=chrome_options)
|
driver = webdriver.Chrome(options=chrome_options)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run.run(driver=driver)
|
run.main(driver=driver)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
finally:
|
finally:
|
||||||
driver.close()
|
driver.close()
|
||||||
|
@ -6,10 +6,11 @@ from selenium.webdriver.remote.webdriver import WebDriver
|
|||||||
import utils
|
import utils
|
||||||
|
|
||||||
|
|
||||||
def run(driver:WebDriver):
|
def main(driver:WebDriver):
|
||||||
driver.set_window_size(1920, 1080)
|
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")
|
width = driver.execute_script("return document.documentElement.scrollWidth")
|
||||||
height = driver.execute_script("return document.documentElement.scrollHeight")
|
height = driver.execute_script("return document.documentElement.scrollHeight")
|
||||||
print(width, height)
|
print(width, height)
|
||||||
utils.screenshot(driver=driver, save_path="./screenshot.png")
|
utils.screenshot(driver=driver, save_path="./tmp/geetest.png")
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 315 KiB After Width: | Height: | Size: 315 KiB |
@ -12,7 +12,7 @@ def screenshot(driver:WebDriver, save_path):
|
|||||||
file_name = os.path.basename(save_path)
|
file_name = os.path.basename(save_path)
|
||||||
if not os.path.exists(_tmp_dir):
|
if not os.path.exists(_tmp_dir):
|
||||||
os.mkdir(_tmp_dir)
|
os.mkdir(_tmp_dir)
|
||||||
|
|
||||||
tmp_file_list = []
|
tmp_file_list = []
|
||||||
try:
|
try:
|
||||||
tmp_file = _tmp_file % (file_name, 0)
|
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")
|
current_h = driver.execute_script("return document.documentElement.clientHeight")
|
||||||
for i in range(1, int(body_h / current_h)):
|
for i in range(1, int(body_h / current_h)):
|
||||||
driver.execute_script(_scroll_to_y % (current_h * i))
|
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))
|
driver.save_screenshot(_tmp_file % (file_name, i))
|
||||||
tmp_file_list.append(_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)
|
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:
|
for tmp in tmp_file_list:
|
||||||
os.remove(tmp)
|
os.remove(tmp)
|
||||||
|
|
||||||
|
|
||||||
def merge_images(image1: str, image2: str,output: str,overlap_size=0):
|
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)
|
img1,img2 = Image.open(image1), Image.open(image2)
|
||||||
size1, size2 = img1.size, img2.size
|
size1, size2 = img1.size, img2.size
|
||||||
merge = Image.new("RGB", (size1[0], size1[1] + size2[1] - size))
|
merge = Image.new("RGB", (size1[0], size1[1] + size2[1] - size))
|
||||||
|
Loading…
Reference in New Issue
Block a user