Java virtual network robot source code

Source: Internet
Author: User
Tags getstream

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 ;}}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.