Article View: cn.bbs.comp.lang.java
Article #12085Re: ���æ����һ����������ij���
From: L&G
Date: Thu, 12 Aug 2004 13:52
Date: Thu, 12 Aug 2004 13:52
308 lines
5960 bytes
5960 bytes
�Ҽ��˼��仰��ϣ���¥���е������������⣬Ҳ��ӭ����ָ��
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();//����URL���openStream()����ö�Ӧ��Input
Stream�����
}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));//
�������岢��ԭʼ���ֽ���ת��ΪUnicode���Բ���.//����unicode��ʲĩ��
//��ԭʼ���ֽ�����Դ����������.getInputStream()��getOutputStream()��.��
�������õ���������
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; //���Dz���Ӧ���ڳ��?���еģ������Dz��������˵ط���
}
public void insertdb(String MTVURL,String MTVname) //��һ�λ�û����û��
��DBo
perate��ʲĩ��
{
// DBoperate writer=new DBoperate(); DBoperateһ��javabean,
//JavaBean��һ��Java�� (class)��ͨ���װ���Ժͷ�����Ϊ����ij�ֹ��ܻ���
����ij��ҵ��Ķ���//�һ�úÿ���javabean,лл��
// 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(;;)
//�߳�����500�����
ʼѭ��
{
try{
test look=new test("http://www.sohu.com");
//test look=new test("http://www.sje.cn"); //
look.getStream(look.urladdr).close(); //�Ƚ������ӣ��ڹ��ϡ�//�Ҿ�
������������������
//����Ӧ����ôд
//look.getover()
//��in.close���뵽getover()��������//��ԭ����д�������û����ģ��Ѿ����Թ�
�ˣ�
�������д��Ӧ����ʵ����Ҫ�ģ�ԭ����д������
һ�ֵ㵽Ϊֹ��д����
Thread.sleep(500); //�߳����ߡ�
}
catch(Exception e){
System.out.println(e.toString());
continue;}}//�����continue������
}
}
--
����L&G,����love and game!
[m[32m�� ��Դ:����ɽ��ˮվ http://bbs.neu.edu.cn��[FROM: 219.216.117.181][m
Technical Details
Message-ID:
<4Db0WE$FS7@bbs.neu.edu.cn>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!news.moat.net!ctu-peer!news.nctu.edu.tw!netnews.csie.nctu.edu.tw!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!NEUShow Full Headers
Complete Article Headers
X-Google-Thread: f6cb0,e4518e6986479dab X-Google-Attributes: gidf6cb0,public X-Google-Language: Chinese,GB Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!news.moat.net!ctu-peer!news.nctu.edu.tw!netnews.csie.nctu.edu.tw!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!NEU From: zhangdazhi@bbs.neu.edu.cn (L&G) Newsgroups: cn.bbs.comp.lang.java Subject: Re: ���æ����һ����������ij��� Date: 12 Aug 2004 13:52:14 GMT Organization: ��ɽ��ˮ Message-ID: <4Db0WE$FS7@bbs.neu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: java/M.1092318734.H0 Lines: 308