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 html
def 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,"货号: ","</li>")
if (r!=null && r.size()>0)
{
println r
}
else
{
println "haah"
}相关阅读:
一些常用的代码评审工具
Atlassian旗下一干team build软件
Jira功能全介绍
项目经验分享
网址、下载地址
Java 字节码解读
Gitlab 安装
博客园设置
mybatis 遇到空串无法判断
Shell 脚本入门原文地址:https://www.cnblogs.com/lexus/p/2636370.html
最新文章
罗马数字转整数
整数转罗马数字
盛最多水的容器
字符串转换整数(atoi)
C语言整型溢出会怎么样
Win10的Cortana小娜反应慢?试试这个方法
error LNK2026 模块对于 SAFESEH 映像是不安全的
C# 调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配 原文:C# 调用导致堆栈不对称。
VC创建DLL, C#调用VC所创建DLL
Android Studio 安装问题。
热门文章
Android studio中为项目添加模块依赖的过程
SurfaceView 与view区别详解
Inno Setup入门(二十三)——Inno Setup类参考(9)
You need to use a Theme.AppCompat theme (or descendant) with this activity问题
写给新手程序员的一封信
程序员技术练级攻略
elipse导入formatter
常用RGB色值
eclipse常用快捷键
fragment