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
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
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 ......
//这是我的定时器类,用来定时执行某段任务;
package com.my.time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
public
class
BugXmlTimer {
public
......
先看一段代码
public class Hello{
public static void main(String[] args){
int i = 5 , j = 2;
System.out.println(i+j);
System.out.println(i-j);
& ......