关键词不能为空

当前您在: 主页 > 英语 >

网络爬虫实验

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-15 14:32
tags:

-

2021年2月15日发(作者:piglet)





湖北文理学院








网络数据挖掘项目解决方案







实验报告





专业班级:








软件工程


1111





















名:







韩江玲





















号:








2011193158














任课教师:







吴中博































2014





9





20






实验


5



网 络数据挖掘解决方案(


X


学时)




一、实验目的与要求



1


、掌握小型项目的架构与设计;



2


、能够独自实现小型项目的开发;



3


、通过实现网络数据挖掘项目,锻炼综合应用能力。



二、预习与准备



1



Swing


编程;

< br>


2


、正则表达式的使用;



3


、网络数据的提取;



4


、分层架构。



三、实验内容



1


、实现网络数据挖掘项目;



2


、撰写实验报告。



四、实验过程



1.


首先明确项目解决思路:



首先建立数据库


?



swing


编写用户界面


?


从数据库获 取


StockId


?


通过


StockId


获取


UR


?


利用


URL


可以得到

< br>URL


里面的内容


?


对该内容进 行解析,


获取需要的数据


?



入数据库。




2.


了解该项目的系统架构:



显示层


:


构建用户界面,提供用户中介



业务逻辑层


:1)


获取


StockId



2)


通过


StockId


获取

URL



3)


通过


URL


提取网页内容;







4)


解析网页内容获取需要的数据;


5)


存入相应的数据库。




数据访问层


:


实现对于数据库的访问,连接,增 加,修改,删除,查询。



3


、开始项目




1


)建数据库




1



(< /p>


2


)建立数据库的连接并定义增删改查操作接口

< br>


public



class


Conn {





private



static


String


dri ver


=



;



private



static


String


url


=



zeroDateTimeBeha vior=convertToNull


;



private



static


String


user


=



;



private



static


String


pas sword


=



;



public



static


Connection getConn(){




Connection conn=


null


;




try


{





Class.

forName


(


driver


) ;





c onn=DriverManager.


getConnection

< br>(


url


,


user


,


password


);




}


catch


(Exception e) {





tackTrace();




}




return


conn;



}






//


获得数据库的连接




public



static


Connection getConnection(String className,String url,String


user,String password){




Connection connection =


null


;




try


{





Cla ss.


forName


(className);





connection = DriverManager.


g etConnection


(url, user, password);







}


catch


(Exception e) {





tackTrace();




}




return


connection;






}





public



static



void


main(String[] args) {




int


i =


updateStockName


(

< br>


华夏



,



);



}









//


更新股票名称




public



static



int


updateStockName(String stockName,String stockId){




Connection connection =


getC onnection


(


driver


,


url


,


user


,


password


);




int


result = 0;




try


{





Statement statement = Statement();





result = eUpdate(




2



'


+s tockName+



+stockId+



);





return


result;




}


catch


(Exception e) {





//


TODO


Auto-generated catch block






result = 0;




}




return


result;






}




//


获得 股票的


id




public



static


List getStockIds() {




List list=


null


;




Connection connection =


getConnection


(


driver


,


url


,


user


,


password


);




try


{





Statement statement = Statement();





ResultSet resultSet = eQuery(



stockbase


);





list =


new


ArrayList();





while


(()){






(ing(1));





}




}


catch


(Exception e) {





//


TODO


Auto-generated catch block






tackTrace();




}







return


list;



}



//



stockmoney


中插入数据




public



static



int


insertStockFH(List list) {




Connection connection =


getC onnection


(


driver


,


url


,


user


,


password


);




int


result = 0




try


{





f or


(


int


i=0;i<();i++){






List stocklist = (i);






for


(


int


j=0;j<(()/5);j++){













Statement statement = Statement();







String

< br>id=(5*j+0).toString()+(5*j+1).toString();













result = eUpdate(



stockmoney(id,stockid,year,qian,songgu,zhuangu) values (


+










+id+



+









(5*j+0)+










+(5*j+1)+



+









(5*j+4)+



+









(5*j+2)+



+









(5*j+3)+



);












}










}








}


catch


(Exception e) {





//


TODO


Auto-generated catch block






result=0;




}



< /p>


System.


out


.println (result);




return


result;



}



3


















}


//


删除所有的钱



public



static


Boolean deleteAllmoney() {



Boolean result =


null


;



Connection connection =


getC onnection


(


driver


,


url


,


user


,


password


);



try


{




Statement statement = Statement();




result = e(



);



}


catch


(SQLException e) {




//


TODO


Auto-generated catch block





tackTrace();



}



return


result;




}


(< /p>


3


)定义


URL


连接接口



public



class


WebConnUtil {




public


String getWebContent(URLConnection urlConnection) {




InputStream is;




StringBuffer sb =


new


StringBuffer();




try


{





is = utStream();





System.

< br>out


.println(is);





InputStreamReader isr=


new


InputStreamReader(is,



);



BufferedReader br=


new


BufferedReader(isr);





String strLine;





while


((strLine=n e())!=


null


)





{






(strLine);





}








}


catch


(IOException e) {





System.


out


.println(



连接失败



);




}




return



new


String(sb);



}


}



4


)对获取的内容进行分析



public



class


Search


extends


Thread{




//


通过


i d


获得名字




public


List getStockNames(Stock stock, List stockId) {







List list =


new


ArrayList();




StringBuffer sb=


new


StringBuffer();




sb=(



股票代码


t


股票名称

< br>n


);



< br>for


(


int


i=0;i<();i++){





String nameurl =



+(i)+



;





sto ck.


jTextField1


.setText(

< p>


正在加载


id



'


+(i)+



的股票名




);





try


{






URL url =


new


URL(nameurl);






URLConnection urlConnection = nnection();






String webcontent =


new



WebConnUtil( ).getWebContent(urlConnection);








4

-


-


-


-


-


-


-


-



本文更新与2021-02-15 14:32,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/655462.html

网络爬虫实验的相关文章

  • 爱心与尊严的高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊严高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊重的作文题库

    1.作文关爱与尊重议论文 如果说没有爱就没有教育的话,那么离开了尊重同样也谈不上教育。 因为每一位孩子都渴望得到他人的尊重,尤其是教师的尊重。可是在现实生活中,不时会有

    小学作文
  • 爱心责任100字作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任心的作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文