最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to location image in web page? - Stack Overflow

programmeradmin9浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论