谁做过新闻采集器,能给我一个吗,我很着急用,就是输入一个网页的地址,把页面中的信息存到数据库中 谁做过新闻采集器,能给我一个吗,我很着急用,就是输入一个网页的地址,把页面中的信息存到数据库中,我的邮件[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 采集代码:(入库就自己写吧)<%@ page contentType="text/html; charset=GBK" %><%@ page import = "java.io.*" %><%@ page import = "java.net.*" %><%@ page import = "java.util.*" %><%! private String Gid = ""; private String Aid = ""; static final private String CONTENT_TYPE = "text/html; charset=GBK"; String filePath = "/home/portal/wwwroot/vod/index.html"; private BufferedReader file; /** * Initialize global variables * @throws ServletException */ public void init() throws ServletException { } /** * * @param in * @param out * @throws Exception */ public static void getURL(String in, OutputStream out) throws Exception { String protocol, local, host, filename; int port; // use the URL class to parse the input URL url = new URL(in); protocol = url.getProtocol(); if (! protocol.equals("http")) // only support http throw new IllegalArgumentException("Only support HTTP protocol."); if ((host = url.getHost()) == null) throw new IllegalArgumentException("Invalid host specified."); // if no port, use the default HTTP port if ((port = url.getPort()) == -1) port = 80; // if no filename, request root directory index if((filename = url.getFile()) == "") filename = "/"; // open a network socket Socket socket = new Socket(host, port); // get input and output streams from the socket InputStream from = socket.getInputStream(); PrintWriter to = new PrintWriter(socket.getOutputStream()); to.print("GET " + filename + " HTTP/1.0\n"); to.print("Accept: */*\n"); to.print("Accept-Language: zh-cn\n"); to.print("Accept-Encoding: gbk, deflate\n"); to.print("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\n"); to.print("Host: " + url.getHost() + "\n"); to.print("Connection: Keep-Alive\n\n"); to.flush(); // read server response and write it to the specified output stream byte[] buf = new byte[4096]; int bytes_read; while((bytes_read = from.read(buf)) != -1) out.write(buf, 0, bytes_read); // close the server and file streams socket.close(); out.close(); } public static String getList(String html) { int StartPos = -1; int EndPos = -1; int Length = -1; StartPos = html.indexOf("<html>",1); EndPos = html.indexOf("</html>",1); return html.substring(StartPos,EndPos); } /** * * @param out * @param html */ public void dispIndex(JspWriter out,String html) throws IOException{ out.println(html); }%><% ByteArrayOutputStream outStream = new ByteArrayOutputStream(); String html = ""; Gid = request.getParameter("Gid"); Aid = request.getParameter("Aid"); if(Gid == null && Aid == null) { try { this.getURL("http://192.168.1.114/vod/indexO.jsp", outStream); html = outStream.toString();//采集到的信息 html = getList(html); } catch (Exception e) { System.err.println("error:" + e); } try { PrintWriter pw = new PrintWriter(new FileOutputStream(filePath)); pw.println(html); pw.close(); } catch(IOException e) { System.out.println("写入文件错误"+e.getMessage()); } response.sendRedirect("http://221.208.250.140/vod/convertToStatic11.jsp");}%> junit能测试通过,emma测试单元覆盖率不能通过 求助:请问谁用过usb身份认证java的开发 socket 多客户问题 为什么把布局设为null后,组件都不见了? jsp连接MySQL数据库的问题 关于JAVA数据库连接池的问题 那为师兄能详细的介绍以下javasmart怎么用吗? JSP编程中怎样查找程序错误啊? Javascript中的switch的bug么?求人解决 java如何调用对方http接口 新手虚心求教 java学到什么程度就能找工作了? 请问如何判断Object map.get(Object key)的返回值为空
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.util.*" %><%!
private String Gid = "";
private String Aid = "";
static final private String CONTENT_TYPE = "text/html; charset=GBK";
String filePath = "/home/portal/wwwroot/vod/index.html";
private BufferedReader file;
/**
* Initialize global variables
* @throws ServletException
*/
public void init() throws ServletException { }
/**
*
* @param in
* @param out
* @throws Exception
*/
public static void getURL(String in, OutputStream out) throws Exception {
String protocol, local, host, filename;
int port; // use the URL class to parse the input
URL url = new URL(in);
protocol = url.getProtocol();
if (! protocol.equals("http")) // only support http
throw new IllegalArgumentException("Only support HTTP protocol."); if ((host = url.getHost()) == null)
throw new IllegalArgumentException("Invalid host specified."); // if no port, use the default HTTP port
if ((port = url.getPort()) == -1) port = 80; // if no filename, request root directory index
if((filename = url.getFile()) == "") filename = "/"; // open a network socket
Socket socket = new Socket(host, port); // get input and output streams from the socket
InputStream from = socket.getInputStream();
PrintWriter to = new PrintWriter(socket.getOutputStream()); to.print("GET " + filename + " HTTP/1.0\n");
to.print("Accept: */*\n");
to.print("Accept-Language: zh-cn\n");
to.print("Accept-Encoding: gbk, deflate\n");
to.print("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\n");
to.print("Host: " + url.getHost() + "\n");
to.print("Connection: Keep-Alive\n\n");
to.flush(); // read server response and write it to the specified output stream
byte[] buf = new byte[4096];
int bytes_read; while((bytes_read = from.read(buf)) != -1)
out.write(buf, 0, bytes_read); // close the server and file streams
socket.close();
out.close();
} public static String getList(String html) {
int StartPos = -1;
int EndPos = -1;
int Length = -1;
StartPos = html.indexOf("<html>",1); EndPos = html.indexOf("</html>",1);
return html.substring(StartPos,EndPos);
}
/**
*
* @param out
* @param html
*/
public void dispIndex(JspWriter out,String html) throws IOException{
out.println(html);
}
%><%
ByteArrayOutputStream outStream
= new ByteArrayOutputStream();
String html = ""; Gid = request.getParameter("Gid");
Aid = request.getParameter("Aid"); if(Gid == null && Aid == null) {
try {
this.getURL("http://192.168.1.114/vod/indexO.jsp", outStream);
html = outStream.toString();//采集到的信息
html = getList(html);
} catch (Exception e) {
System.err.println("error:" + e);
}
try { PrintWriter pw = new PrintWriter(new FileOutputStream(filePath)); pw.println(html); pw.close(); } catch(IOException e) { System.out.println("写入文件错误"+e.getMessage());
} response.sendRedirect("http://221.208.250.140/vod/convertToStatic11.jsp");
}
%>