admin管理员组文章数量:1022752
I want cut image from web page by python + Selenium, and remote debug by mstsc. Below is my code fragment:
image_data = self.driver.get_screenshot_as_png()
screenshot = Image.open(BytesIO(image_data))
screenshot.save('screenshot.png')
element = self.driver.find_element(By.CSS_SELECTOR,'myselect')
top = element.location['y']
bottom = element.location['y'] + element.size['height']
left = element.location['x']
right = element.location['x'] + element.size['width']
result = screenshot.crop((left,top,right,bottom))
But I can't get the image which I want. I open screenshot.png and find the real position by mouse, the value of (left,top,right,bottom) I got is different from the value calculated by the above code. So how can I get the real position of the image I want in web page?
I want cut image from web page by python + Selenium, and remote debug by mstsc. Below is my code fragment:
image_data = self.driver.get_screenshot_as_png()
screenshot = Image.open(BytesIO(image_data))
screenshot.save('screenshot.png')
element = self.driver.find_element(By.CSS_SELECTOR,'myselect')
top = element.location['y']
bottom = element.location['y'] + element.size['height']
left = element.location['x']
right = element.location['x'] + element.size['width']
result = screenshot.crop((left,top,right,bottom))
But I can't get the image which I want. I open screenshot.png and find the real position by mouse, the value of (left,top,right,bottom) I got is different from the value calculated by the above code. So how can I get the real position of the image I want in web page?
本文标签: pythonHow to location image in web pageStack Overflow
版权声明:本文标题:python - How to location image in web page? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745577365a2157102.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论