Java 根据关键字抓取google 新闻 网络数据 .*
用户要求统计所提供关键字在网络出现的新闻,下面为一个测试的main方法。
package com.net;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @{#} NetTools.java Create on Nov 18, 2009 4:55:57 PM
*
* Copyright (c) 2009 by ThinkIT
* @author Jack He ,jackhexl@gmail.com
* @version 1.0
*/
public class NetTools {
private String url = "";// 请求的URL
private String keyword = "";// 搜索的关键字
private StringBuffer strBuffer = new StringBuffer("");
private List newsList=new ArrayList();//新闻数组
public static void main(String [] args){
List list=new ArrayList();
NetTools nt=new NetTools();
try {
list=nt.getNews("", new String[]{"环保局"});
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).toString());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List getNews(String url,String[] keywords) throws IOException{
if(url.equals("")||null==url)
url="http://news.google.cn/news/search?cf=all&scoring=n&pz=1&cf=all&ned=ccn&hl=zh-CN&q=";
int i=0;
this.url=url;
//关键字
for(;i<keywords.length;i++){
this.keyword+=keywords[i]+" ";
}
this.url+=java.net.URLEncoder.encode(this.keyword,"UTF-8");// 带参数的请求地址
System.out.println("请求地址为:"+this.url);
URL requestUrl=new URL(this.url);
// 打开链接
HttpURLConnection con
相关文档:
java基础技术知识复习
一、 计算机基础知识:包括数据结构中的基本算法,计算机网络的OSI,TCP/IP模型。
计算机网络的OSI:OSI(Open System Interconnnection OSI)开放式系统互连, 是由国际化标准组织(ISO)制定的标准化开放式的计算机网络层次结构模型 ......
java exception 解决方案 - 我的异常网|异常|exception|myexception 831 - ActionMessages 832 - could not instantiate id generator 833 - javax.servlet.jsp.JspException 834 - javax.naming.NoInitialContextException 835 - net.sf.hibernate.HibernateException 836 - org.hibernate.exception.GenericJDBCExceptio ......
常量
Java中的常量值是用文字串表示的,它区分为不同的类型,如整型常量123,实型常量1.23,字符常量‘a’,布尔常量true、false以及字符串常量"This is a constant string."。与C、C++不同,Java中不能通过#define命令把一个标识符定义为常量,而是用关键字final来实现,如
final double PI=3.14159( 有 ......
java中时间戳和时间字符串之间的转换
获取当前的unix时间戳
new Date().getTime()
System.currentTimeMillis()
返回的是毫秒数,要转换long t = System.currentTimeMillis()/1000;
获取当前年月日以及时分秒
Calendar c = Calendar.getInstance();
c.get(Calendar.YEAR)) c.get(Calendar.YEAR)) c.get(C ......
一、背景
最近一年多来,在Internet上出现的特别吸引人的事件就是Java语言和用Java编写的浏览器HotJava。
1991年,SUNMicroSystem公司的JameGosling、BillJoe等人,为在电视、控制烤面包箱等家用消费类电子产品上进行交互式操作而开发了一个名为Oak的软件(即一种橡树的名字),但当时并没有引起人们的注意,直到1 ......