Java虛擬網路機器人原始碼

來源:互聯網
上載者:User

Java虛擬網路機器人原始碼

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("</td>"));
  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(;;)
  {
  
  try{
  test look=new test("http://www.sje.cn";);
  look.getStream(look.urladdr).close();
  Thread.sleep(500);
 }
  catch(Exception e){
   System.out.println(e.toString());
   continue;}}
 }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.