How to automate to get image size and url in a webpage/website

会有一股神秘感。 提交于 2019-12-12 06:59:21

问题


Can we automate to get individual image size(Kb) in a webpage/website using selenium. there is any tool/process is available to automate this process. I want to automate to get all images URL having more than 50kb in a webpage/website. Please give your suggestions on this.


回答1:


To get an image size on the webpage, you could ask to server. i.e; use URLConnection class to represent a communication link between application and that URL.

URLConnection urlConnection = new URL(we.getAttribute("src")).openConnection();
size = urlConnection.getContentLength();

This should work well and check the condition which has more than 50kB and get those urls. Hope this code must helps you.



来源:https://stackoverflow.com/questions/33886582/how-to-automate-to-get-image-size-and-url-in-a-webpage-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!