java下载安装失败(groovy java 下载中文乱码网页办法)
URL url = new URL("http://fatkun.com"); // 读取源码 //读取中文时 ,使用Reader类是每次读出两个字节的 ,不会出现中文乱码 InputStreamReader in = new InputStreamReader(url.openStream(), "UTF-8"); char[] buf = new char[2048];//缓存 StringBuffer sb = new StringBuffer(); int len = 0; while ((len = in.read(buf)) != -1) {//当没到文档尽头继续读取 sb.append(buf, 0, len); }
import groovy.json.JsonSlurper;
import java.util.regex.*;
import sun.net.www.protocol.http.HttpURLConnection;
System.properties.putAll( ["http.proxyHost":"10.10.243.140", "http.proxyPort":"808"] )URL url = new URL("http://detail.tmall.com/item.htm?spm=a220z.1000880.0.44&id=16761700638");
// 读取源码
//读取中文时,使用Reader类是每次读出两个字节的 ,不会出现中文乱码
InputStreamReader _in = new InputStreamReader(url.openStream(), "GBK");
char[] buf = new char[2048];//缓存
StringBuffer sb = new StringBuffer();
int len = 0;
while ((len = _in.read(buf)) != -1) {//当没到文档尽头继续读取
sb.append(buf, 0, len);
}
def html=sb.toString()
print html
def out = new File(/home/mlzboy/aaa.html)
out.append htmldef cut(ohtml,start=null,end=null)
{
def html=ohtml
if(html==null || html.trim().length()==0 )
return null
if(start!=null)
{
def s=html.indexOf(start)if(s==-1)
return null
else
html=html[s+start.length()..-1]
}if(end!=null)
{
def e=html.indexOf(end)
if(e==-1)
return null
else
html=html[0..e-1]
}
return html
}def r=cut(html,"货号: ","")
if (r!=null && r.size()>0)
{
println r
}
else
{
println "haah"
}
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!