如何使用英特尔®oneAPI工具实现PyTorch 优化,直播火热报名中>>>
url = new URL(Url); try { URLConnection urlConn = url.openConnection(); // 打开网站链接s urlConn.setRequestProperty("User-Agent","Mozilla/5.0"); InputStream in=urlConn.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8")); // 实例化输入流,并获取网页代码 return br; } catch (IOException eio1) { System.out.println(eio1); return null; }
这是我获取网页源码的部分代码,我这里没有从网页中获取charset,直接写的UTF-8~因为我现在测试出问题的网站恰恰是出问题的UTF-8编码的www.mop.com~
在获取猫扑网页源码的时候,出现了很奇特的现象,一会乱码一会正常...而且大多数时候获取不到源码而是乱码...(我不断在运行)这是为什么!?我明明设定的是按UTF-8转化的啊~而且Mop主页确实是charset=utf-8的啊~~为什么会出现乱码的状况呢????????求助啊!!!!!!!!!!!!!!!!
curl "www.mop.com" -I
HTTP/1.1 200 OK
Server: nginx/0.8.32Date: Sun, 18 Nov 2012 04:49:14 GMT
Content-Type: text/html
Connection: keep-alive
Expires: Sun, 18 Nov 2012 04:52:14 GMT
Cache-Control: max-age=180
Content-Encoding: gzip
默认GZIP压缩过了 要先解压缩,然后才能输出 看到的才不是乱码