如何自动获取网页/网站中的图片大小和网址 [英] How to automate to get image size and url in a webpage/website
问题描述
我们可以使用硒自动获得网页/网站中单个图像的大小(Kb)吗?没有任何工具/过程可用于自动化此过程.我想自动获取网页/网站中具有超过50kb的所有图像URL.请对此提出您的建议.
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.
推荐答案
要在网页上获取图像大小,您可以要求服务器. IE;使用URLConnection类表示应用程序与该URL之间的通信链接.
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();
这应该可以正常工作,并检查具有超过50kB的条件并获取那些url.希望这段代码对您有所帮助.
This should work well and check the condition which has more than 50kB and get those urls. Hope this code must helps you.
这篇关于如何自动获取网页/网站中的图片大小和网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!