谷歌浏览器实现网页截屏
from selenium import webdriver
import time
import os,shutil
def main():
driver_path = r"C:\Users\user\Desktop\chromedriver.exe" #指定chromedriver.exe路径
options = webdriver.ChromeOptions()
driver =webdriver.Chrome(executable_path=driver_path)
driver.get("url网址")
body = driver.find_element_by_xpath('//tr[@valign="top"]') #想要截图区域的xpath
image_name = time.strftime('%Y-%m-%d %A')
body.screenshot("%s.png"%image_name) #截图保存为
mv_file(image_name)
#图片移动
def mv_file(image_name):
source_img = os.getcwd()
if os.path.exists(r'..\..\..\Desktop\截图'):
shutil.move('.\\'+"%s.png"%image_name,'..\\..\\..\\Desktop\\截图\\'+"%s.png"%image_name)
else:
print("不存在截图文件夹")
if __name__ == '__main__':
main()
python实现网页截图,通过xpath选取截图区域
最新推荐文章于 2024-07-06 02:51:43 发布