如何计算一个页面的总大小与附加文件和脚本 [英] How to calculate total size of a page with additional files and scripts

查看:313
本文介绍了如何计算一个页面的总大小与附加文件和脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下是否有可能在C#中,一个特定的网站内容大小,得到编程。按大小我的意思是:该网站包括头部分或身体等引用的所有图像和脚本的全尺寸。例如,如果我们有一个网站 http://www.google.com 我想用它弄的,包括总规模标志,脚本所指向到,等,因为这将是psented给用户$ p $不仅仅是主网页

I would like to ask if it's possible to get programmatically in C#, a specific site content size. By size I mean: the full size of the site including all images and scripts referenced in the head section or body and so on. For example if we have a site http://www.google.com I want o get it's total size including the logo, scripts refered to, and so on as it will be presented to the user not just the main page.

下面是一个图片我的意思:(点击查看原图)

Here is a picture what I mean: (click for full size)

如果我们使用IE 9 IE开发工具,并开始捕捉对网络会话流量,比我们打google.com,它显示加载的总文件(.js文件,.png和等)和时间装载以​​毫秒为单位。

If we use IE Developer tool in IE 9, and start capturing traffic on the network session, than we hit google.com and it shows the total files loaded (.js, .png, and so on) and the time of loading in milliseconds.

我试图用一个WebRequest的做同样的事情,但我得到的只有43KB,而不是101 IE浏览器的开发工具得到。

I tried to do something similar using a webrequest but i get only 43kb instead of 101 as IE developer tool gets.

下面是code:

WebRequest request = WebRequest.Create(textBox2.Text.ToString());     
request.Credentials = CredentialCache.DefaultCredentials;           
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();      
StreamReader reader = new StreamReader(dataStream);          
string responseFromServer = reader.ReadToEnd();         
byte[] bytes = Encoding.ASCII.GetBytes(responseFromServer);
MessageBox.Show(ConvertSize(responseFromServer.Length) + "  -  " + responseFromServer.Length.ToString());
reader.Close();
dataStream.Close();
response.Close();

我怎样才能获得包括使用的所有图像,js和其他文件/在特定页面引用的网站的总大小?非常感谢!

How can I get the total size of a site including all images, js and additional files used/referenced in that specific page? Thanks a lot!

推荐答案

您的WebRequest是刚开的HTML。这不是解析获取任何引用的文件(图片,CSS,JavaScript的包括,等等)。控制如 web浏览器控件可以让您自动浏览器

Your WebRequest is just getting the HTML. It's not parsing to fetch any referenced files (images, CSS, javascript includes, etc). Controls such as the WebBrowser control can allow you to automate a browser

这篇关于如何计算一个页面的总大小与附加文件和脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆