Java virtual network robot source code
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 ("file name:") + 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.exe SQL (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 ;}}
}
}