# xpath截取元素,并保存到本地 canvasEle1=driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/canvas[1]') canvasEle2=driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/canvas[2]') canvasEle3=driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/canvas[3]') canvas1=canvasEle1.screenshot_as_png # 截取后直接是二进制 canvas2=canvasEle2.screenshot_as_png canvas3=canvasEle3.screenshot_as_png with open(r"C:\Users\Administrator\Desktop\工作\code\a_cw_web\cw_version7\test_photo\img\1.jpg", mode="wb")as f: f.write(canvas1) with open(r"C:\Users\Administrator\Desktop\工作\code\a_cw_web\cw_version7\test_photo\img\2.jpg", mode="wb")as f: f.write(canvas2) with open(r"C:\Users\Administrator\Desktop\工作\code\a_cw_web\cw_version7\test_photo\img\3.jpg", mode="wb")as f: f.write(canvas3) 参考: https://www.cnblogs.com/lihongtaoya/p/16759942.html
标签:xpath,body,截取,selenium,html,本地,div,cw From: https://www.cnblogs.com/hyd666kkk/p/17187414.html