是否可以在c#中压缩网站HTML? [英] Is it possible to compress a sites HTML in c# ?

查看:74
本文介绍了是否可以在c#中压缩网站HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以用C#或任何其他语言(例如C ++,PHP和java)来获取和压缩网站HTML代码. HTML代码,例如https://www.google.com.pk/search?q=msdn+forums&oq=msdn+forums&aqs=chrome..69i57j69i60j69i57j69i60l3.1654j0j7&sourceid=chrome&ie = UTF-8

I was wondering if it is possible to fetch and compress a sites HTML code in C# or any other language like C++, PHP , java . HTML code like the source code  of https://www.google.com.pk/search?q=msdn+forums&oq=msdn+forums&aqs=chrome..69i57j69i60j69i57j69i60l3.1654j0j7&sourceid=chrome&ie=UTF-8

推荐答案

为什么?您可以从HTML中删除注释和空格,但实际上并不会改变任何内容.除非您在将请求发送回客户端之前在Web服务器上执行此操作,否则浏览器仍将获取完整的HTML.在客户端 渲染也将基本相同.

Why? You could strip out comments and whitespace from HTML but it really isn't going to change anything. Unless you did it on the web server before the request was sent back to the client the browser would still get the full HTML. On the client side the rendering is going to be basically the same as well.

我不知道有任何程序可以执行此操作,但是您可以使用HtmlAgilityPack或类似的HTML解析器来枚举HTML的元素,并剔除不需要的内容.您只需要小心,因为在某些情况下去除空格可能会破坏 HTML.

I'm not aware of any program that does that but you can use HtmlAgilityPack or similar HTML parser to enumerate the elements of the HTML and strip out the things you don't want. You just need to be careful as stripping out whitespace in some cases can break the HTML.

迈克尔·泰勒
http://www.michaeltaylorp3.net

Michael Taylor
http://www.michaeltaylorp3.net


这篇关于是否可以在c#中压缩网站HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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