WEB开发网
开发学院WEB开发Jsp Java趣味“Java网络机器人” 阅读

Java趣味“Java网络机器人”

 2008-01-05 19:22:27 来源:WEB开发网   
核心提示:package auto;import java.net.*;import java.sql.*;import java.io.*;import java.util.*;//import db.*;public class test extends Thread{URL weburl;String urladdr;pu

  package auto;
  import java.net.*;
  import java.sql.*;
  import java.io.*;
  import java.util.*;
  //import db.*;
  public class test extends Thread{
  URL weburl;
  String urladdr;
  public test()
  {}
  public test(String urladdr,URL weburl)
  {
  this.urladdr=urladdr;
  this.weburl=weburl;
  }
  public test(String urladdr)
  {
  try{
  this.urladdr=urladdr;
  //weburl=new URL(urladdr);
  this.start();
  }
  catch(Exception e){System.out.PRintln(e.toString());}
  }
  public InputStream getStream(String url)
  {
  try{
  //urladdr=url;
  URL tempurl=new URL(url);
  
  return tempurl.openStream();
  }catch(Exception e){System.out.println("hello");}
  return null;
  }
  public void run()
  {
  while(true)
  { try{
  getStream(urladdr);
  Thread.sleep(200);
  }catch(Exception e){}
  }
  }
  public String getStr(InputStream in)
  {
  try{
  StringBuffer temp=null;
  BufferedReader buffer=new BufferedReader(new InputStreamReader(in));
  String tempstr="";
  String strsum="";
  while ((tempstr=buffer.readLine())!=null)
  {
  strsum=strsum+tempstr;
  
  }
  buffer.close();
  //in.close();
  return strsum;}
  catch(Exception e){System.out.println("shit");
  }
  return "";
  }
  public String getMTVURL(String Html)
  { try{
  String temp=html.substring(html.lastIndexOf("../")+3);
  temp=temp.substring(0,temp.indexOf("\""));
  temp="http://movies.v111.com/movies/film/play.asp?Id=30959";+temp;
  
  temp=temp.trim();
  
  
  return temp; }catch(Exception e){System.out.println(e.toString());}
  return null;
  }
  public String getMTVname(String html)
  {
  try{
  String temp=html.substring(html.indexOf("作品名:")+4);
  temp=temp.substring(0,temp.indexOf(""));
  temp=temp.trim();
  return temp;}
  catch(Exception e){System.out.println("hello");}
  return null;
  }
  public void insertdb(String MTVURL,String MTVname)
  {
  // DBOperate writer=new DBoperate();
  // String insert="insert into mtvList(mtvname,mtvurl)values('"+MTVname+"','"+MTVURL+"')";
  // writer.exesql(insert);
  }
  public void getover()
  {
  InputStream in=getStream(urladdr);
  String content=getStr(in);
  String url=getMTVURL(content);
  String name=getMTVname(content);
  insertdb(url,name);
  }
  public static void main(String[] avg)
  {
  for(;

Tags:Java 趣味 Java

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接