当前位置: 首页 > news >正文

做视频网站成本高吗响应式模版移动优化

做视频网站成本高吗,响应式模版移动优化,微信小程序的制作流程,seo策略什么意思获取页面的编码格式的三种方式#xff1a; 根据Response中的header获取编码格式根据页面标签中的meta获取根据页面内容识别自动识别出编码格式#xff0c;经过测试准确率比较高 三种方式可以结合使用#xff0c;由于inputStream不能够被复用#xff0c;但是inputStrem没有…获取页面的编码格式的三种方式 根据Response中的header获取编码格式根据页面标签中的meta获取根据页面内容识别自动识别出编码格式经过测试准确率比较高 三种方式可以结合使用由于inputStream不能够被复用但是inputStrem没有clone方法也导致无法克隆 因此需要流转化这种方式多重比较需要重复进行流转化。 依赖包 我的资源 工具类 /*** 获取页面的编码格式1.根据Response中的header获取编码格式2.根据页面标签中的meta获取3.根据页面内容识别自动识别出编码格式经过测试准确率比较高三种方式可以结合使用目前GFCrawer是使用了meta一种由于inputStream不能够被复用但是inputStrem没有clone方法也导致无法克隆因此需要流转化这种方式多重比较需要重复进行流转化*/ package charset;import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.nio.charset.Charset; import java.util.List; import java.util.Map;import org.apache.commons.io.IOUtils;import info.monitorenter.cpdetector.io.ASCIIDetector; import info.monitorenter.cpdetector.io.ByteOrderMarkDetector; import info.monitorenter.cpdetector.io.CodepageDetectorProxy; import info.monitorenter.cpdetector.io.JChardetFacade; import info.monitorenter.cpdetector.io.ParsingDetector; import info.monitorenter.cpdetector.io.UnicodeDetector;/*** author weijie 2019年5月8日*/ public class GFCrawerCharset {public static void main(String[] args) {// 判断乱码System.out.println(------判断乱码-------);//gb2312String url http://www.people.com.cn/;//utf-8String url2 https://blog.csdn.net/dreamzuora;String errorHtml GFCrawer.GetContent(url, utf-8);String succHtml GFCrawer.GetContent(url2);System.out.println(error: errorHtml.substring(100, 300));System.out.println(succ: succHtml.substring(1000, 1100));boolean b isErrorCodes(errorHtml);boolean b2 isErrorCodes(succHtml);System.out.println(b);System.out.println(b2);// meta获取编码System.out.println(-------meta获取编码------);System.out.println(url \t getCharsetByMeta(url));System.out.println(url2 \t getCharsetByMeta(url2));// responseHeader获取后端返回的contentType但是很多网站不会明确返回System.out.println(-------后端头信息编码结果------);System.out.println(url \t getAutoCharsetByHeader(url));System.out.println(url2 \t getAutoCharsetByHeader(url2));// 自动判断编码类型System.out.println(-------识别文本信息编码------);cdpInit();System.out.println(url \t getAutoCharsetByURL(url));System.out.println(url2 \t getAutoCharsetByURL(url2));}// 解析页面内容自动识别编码类型public static CodepageDetectorProxy cdp null;static {cdpInit();}public static void cdpInit() {cdp CodepageDetectorProxy.getInstance();cdp.add(JChardetFacade.getInstance());cdp.add(ASCIIDetector.getInstance());cdp.add(UnicodeDetector.getInstance());cdp.add(new ParsingDetector(false));cdp.add(new ByteOrderMarkDetector());}/*** 判断是否乱码 加上html的判断会出错* * param html* return*/public static boolean isErrorCodes(String str) {for (int i 0, len str.length(); i len; i) {char c str.charAt(i);// 当从Unicode编码向某个字符集转换时如果在该字符集中没有对应的编码则得到0x3f即问号字符?//从其他字符集向Unicode编码转换时如果这个二进制数在该字符集中没有标识任何的字符则得到的结果是0xfffd//System.out.println(--- (int) c);if ((int) c 0xfffd) {// 存在乱码//System.out.println(存在乱码 (int) c);return true;}}return false; }/*** 通过流判断编码格式* * param in* return*/public static String getAutoCharsetByInputStream(InputStream in) {String code null;ByteArrayInputStream bais null;try {bais new ByteArrayInputStream(IOUtils.toByteArray(in));Charset charset cdp.detectCodepage(bais, 2147483647);bais.close();code charset.name();} catch (IOException e) {e.printStackTrace();}return code;}/*** 通过url判断* * param href* return*/public static String getAutoCharsetByURL(String href) {URL url;String code null;try {url new URL(href);Charset charset cdp.detectCodepage(url);code charset.name();} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return code;}/*** 从mata获取编码格式* * param url* return*/public static String getCharsetByMeta(String href) {String charset null;URL url null;try {url new URL(href);} catch (MalformedURLException e) {e.printStackTrace();url null;} if(url null){return null;}HttpURLConnection httpConnection null;try {httpConnection (HttpURLConnection) url.openConnection();} catch (IOException e) {e.printStackTrace();httpConnection null;}if(httpConnection null){return null;}httpConnection.setRequestProperty(User-Agent,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727));InputStream input null;try {input httpConnection.getInputStream();input.read();BufferedReader reader new BufferedReader(new InputStreamReader(input));while (reader.ready()) {String line reader.readLine();if (line.contains(http-equiv) line.contains(charset)) {String tmp line.split(;)[1];charset tmp.substring(tmp.indexOf() 1, tmp.indexOf(\));break;} else {continue;}}reader.close();} catch (Exception e) {e.printStackTrace();input null;}return charset;}/*** 从mata获取编码格式* * param url* return*/public static String getCharsetByMeta(InputStream inputStream) {String charset null;try {BufferedReader reader new BufferedReader(new InputStreamReader(inputStream));while (reader.ready()) {String line reader.readLine();if (line.contains(http-equiv) line.contains(charset)) {String tmp line.split(;)[1];charset tmp.substring(tmp.indexOf() 1, tmp.indexOf(\));} else {continue;}}reader.close();return charset;} catch (MalformedURLException e) {e.printStackTrace();return charset;} catch (IOException e) {e.printStackTrace();return charset;}}/*** 从header中获取页面编码* * param strUrl* return*/public static String getAutoCharsetByHeader(String href) {String charset null;URL url null;try {url new URL(href);} catch (MalformedURLException e) {e.printStackTrace();url null;} if(url null){return null;}HttpURLConnection httpConnection null;try {httpConnection (HttpURLConnection) url.openConnection();} catch (IOException e) {e.printStackTrace();httpConnection null;}if(httpConnection null){return null;}httpConnection.setRequestProperty(User-Agent,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727));// 获取链接的headerMapString, ListString headerFields httpConnection.getHeaderFields();// 判断headers中是否存在Content-Typeif (headerFields.containsKey(Content-Type)) {// 拿到header 中的 Content-Type [text/html; charsetutf-8]ListString attrs headerFields.get(Content-Type);String[] as attrs.get(0).split(;);for (String att : as) {if (att.contains(charset)) {charset att.split()[1];}}}return charset;}/*** 从header中获取页面编码* * param strUrl* return*/public static String getCharsetByHeader(URLConnection urlConn) {String charset null;// 获取链接的headerMapString, ListString headerFields urlConn.getHeaderFields();// 判断headers中是否存在Content-Typeif (headerFields.containsKey(Content-Type)) {// 拿到header 中的 Content-Type [text/html; charsetutf-8]ListString attrs headerFields.get(Content-Type);String[] as attrs.get(0).split(;);for (String att : as) {if (att.contains(charset)) {charset att.split()[1];}}}return charset;} }
http://www.zqtcl.cn/news/826262/

相关文章:

  • 哈尔滨做网站哪家好强企业邮箱登录入口163
  • 网站点击率原因学php到做网站要多久
  • 哪里有创建网站的长沙网站seo技巧
  • 影楼公共网站wordpress提交360
  • 哪有做网站东莞中堂网站建设
  • 什么叫域名访问网站网络运营管理
  • 深圳网络推广网站泰安网站建设公司
  • 淄博网站建设铭盛信息如何注册一个app平台
  • 深圳网站的建设维护公司成功的网站必须具备的要素
  • wordpress主题站主题小型企业网站的设计与实现
  • 长沙专门做网站公司怎么进入网站管理页面
  • 做网站企业的发展前景东莞免费企业网站模板推广
  • 国外做锅炉的网站wordpress批量提交表单
  • 浙江省建设科技推广中心网站兼职做网站这样的网站
  • 网站开发前端培训最有设计感的网站
  • 巢湖有没有专门做网站的公司深圳 网站设计公司价格
  • 信息图表设计网站站长工具使用方法
  • 建站赔补用python做网站优点
  • 个人免费域名空间建站淄博网络公司全网推广
  • 企业信息年报系统南昌做seo的公司
  • 门户网站开发模板动漫设计与制作设计课程
  • vip网站怎么做有关设计的网站
  • wordpress网站第一次打开慢那个网站做视频没有水印
  • 做外贸英语要什么网站网站整体设计风格
  • 高端网站开发哪里好2022最新新闻素材摘抄
  • 网站建设实训个人深圳做营销网站的公司哪家好
  • 广州seo网站策划wordpress关闭主题提示
  • 做门票售卖网站怎么制作自己的水印
  • 网站绑定两个域名怎么做跳转asp 网站后台
  • 百度网站怎么做的赚钱吗郑州资助app下载