JAVA 爬网页用 例如:http://www.126.com
/*
Function name: myGetHttpFile2
Description: 爬网页用
Input: URL 例如:http://www.126.com
Output: 字符串,网页的HTML
*/
public String myGetHttpFile2(String url){
String authentication=null;
ArrayList al=new ArrayList();
String PageURL = url;
PageURL = url ;
ArrayList urlCollection=new ArrayList();
Hashtable ht=new Hashtable();
//代理,如果要穿过代理将下面注释取消
//ht=System.getProperties();
//authentication = "Basic " + new sun.misc.BASE64Encoder().encode("代理的用户:代理的密码".getBytes());
//ht.put("proxySet", "true");
//ht.put("proxyHost", "172.16.20.2");
//ht.put("proxyPort", "80");
String urlSource=PageURL;
StringBuffer htmlBuffer=new StringBuffer();
String returnStr=null;
int codeStart=0;
int codeEnd=0;
int linkCount=0;
String getURL=null;
String realURL=null;
String urlText=null;
int from=0;
int lenURL=0;
int firstLink=0;
int endLink=0;
boolean isNewsLink=false;
try
{
URL su = new URL (urlSource);
URLConnection conn = su.openConnection();
//conn.setRequestProperty("Proxy-Authorization", authentication);
InputStream imageSource=new URL(urlSource).openStream();
int ch;
while((ch=imageSource.read())>-1)
{
htmlBuffer.append((char)ch);
}
imageSource.close();
returnStr= new String(htmlBuffer);
returnStr=new String(returnStr.getBytes("ISO8859_1"),"GBK");
}
catch(Exception e)
{
}
if(returnStr!=null){
return returnStr ;
}else{
return "empty" ;
}
}
相关文档:
jvm classLoader architecture:
1. Bootstrap ClassLoader/启动类加载器
主要负责jdk_home/lib目录下的核心 api 或 -Xbootclasspath 选项指定的jar包装入工作。
2. Extension ClassLoader/扩展类加载器
主要负责jdk_home/lib/ext目录下的jar包或 -Djava.ext.dirs 指定目录下的jar包装入工作。
3 ......
先贴一段
Java
基本结构
Java
结构包括四个不同而又相关的部分:
Java
语言、
class
文件格式、应用程序接
口、虚拟机
其中,虚拟机的主要任务是在程序运行中需要的时候调用
class
文件并执行其中的字节码。一个
Java
应
用有两种
class loader
:
the system class loader
和
class loader objects
......
一、什么是Java事务
通常的观念认为,事务仅与数据库相关。
事务必须服从ISO/IEC所制定的ACID原则。ACID是原子性(atomicity)、一致性(consistency)、隔离性(isolation)和持久性(durability)的缩写。事务的原子性表示事务执行过程中的任何失败都将导致事务所做的任何修改失效。一致性表示当事务执行失败 ......
字符串
1、获取字符串的长度
length()
2 、判断字符串的前缀或后缀与已知字符串是否相同
前缀 startsWith(String s)
后缀 endsWith(String s)
3、比较两个字符串
equals(String s)
4、把字符串转化为相应的数值
int型 Integer.parseInt(字符串)
......