1,背诵单词:finite 有限的,设计图,计划 merely 仅仅,只不过 norm 准则,规范,准则 soul灵魂,精力 faculty才能;学院 congress (代表)大会 hinder 阻止,妨碍 loaf 一个面包 outfit 用具,机构 wound创伤,伤口 Alloy 合金 waterproof防水的,耐水的 immediate立即的,即时的 clutch抓住,攫住,掌握 salesman售货员,推销员 stem 茎,干 cruel 残忍的,残酷的 dump倾倒,倾卸 restless不平静的;坐立不安的 such这样的;上述的 strain 拉紧;紧张;扭伤 pregnant 怀孕的,孕育的的 conversation会话,谈话
2,做将文件内的数据存入mysql,从首都之窗爬取了一万两千多条信件详细页面数据。直到2015年1月
package com.lq.dao; import com.lq.bean.XinJian; import com.lq.file.LocalFile; import java.sql.*; import java.util.List; public class AddToMySql { private static String DriverName="com.mysql.jdbc.Driver"; private static String UName="root"; private static String Upwd="root"; private static String Url="jdbc:mysql://192.168.25.1:3306/xinjian?useUnicode=true&characterEncoding=UTF-8"; public boolean exit(String id) //根据Id查询是否存在 如果存在返回true,不存在返回false { //System.out.println(query(id)); return query(id)==1?true:false; } public int query(String Id) //查询是否存在;存在return 1;否存在return 0; { XinJian xinJian=null; Connection conn=null; PreparedStatement pstmt=null; ResultSet result=null; int count=-1; try { Class.forName(DriverName); conn=DriverManager.getConnection(Url, UName, Upwd); String sql="select count(*) from xinjian where Id=?"; pstmt= conn.prepareStatement(sql); pstmt.setString(1,Id); result=pstmt.executeQuery(); if(result.next()){ count=result.getInt(1); System.out.println("已存在"); } if(count>0) return count; } catch(ClassNotFoundException e) { e.printStackTrace(); return count; } catch (SQLException e) { e.printStackTrace(); return count; } catch(Exception e) { e.printStackTrace(); return count; } finally { try { if(result!=null) result.close(); if(pstmt!=null) pstmt.close(); if(conn!=null) conn.close(); } catch(SQLException e) { e.printStackTrace(); } } return count; } public boolean Add(XinJian xinJian) //添加信息 { Connection conn=null; PreparedStatement pstmt=null; try { AddToMySql addToMySql=new AddToMySql(); //System.out.println(addToMySql.exit(xinJian.getId())); if(addToMySql.exit(xinJian.getId())!=true) { //System.out.println("2"); Class.forName(DriverName); conn = DriverManager.getConnection(Url, UName, Upwd); String sql = "insert into xinjian(Id,typet,massage,statue,send_time,addresser,asker,details,answering,answer_time,reply) values(?,?,?,?,?,?,?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, xinJian.getId()); pstmt.setString(2, xinJian.getType()); pstmt.setString(3, xinJian.getMassage()); pstmt.setString(4, xinJian.getStatue()); pstmt.setString(5, xinJian.getSend_time()); pstmt.setString(6, xinJian.getAddresser()); pstmt.setString(7, xinJian.getAsker()); pstmt.setString(8, xinJian.getDetails()); pstmt.setString(9, xinJian.getAnswering()); pstmt.setString(10, xinJian.getAnswer_time()); pstmt.setString(11, xinJian.getReply()); int connt = pstmt.executeUpdate(); if (connt > 0) { System.out.println("保存成功"); return true; } else { System.out.println("已存在"); return false; } } else return false; } catch(ClassNotFoundException e) { e.printStackTrace(); return false; //系统异常 } catch(SQLException e) { e.printStackTrace(); return false; } catch(Exception e) { e.printStackTrace(); return false; } finally { try { if(pstmt!=null){ pstmt.close(); conn.close(); } } catch(SQLException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } } } public void Run(){ try { LocalFile localFile=new LocalFile(); AddToMySql addToMySql=new AddToMySql(); String [] strs = localFile.read_xinjian_local("xinjian.txt"); String[] str=null; for(int i=0;i<strs.length;i++){ str=strs[i].split("&&"); XinJian xinJian=null; // System.out.println(str[0]+str[10]); // System.out.println("------------------------------------------------------"); xinJian=new XinJian(str[0],str[1],str[2],str[3],str[4],str[5],str[6],str[7],str[8],str[9],str[10]); addToMySql.Add(xinJian); // System.out.println(xinJian.toString()); } //System.out.println(str.length); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args){ AddToMySql addToMySql=new AddToMySql(); //addToMySql.exit("AH19080800081"); addToMySql.Run(); System.out.println("finish"); } }
public String[] read_xinjian_local(String files) throws Exception { File file =new File("outfile"+File.separator+files); FileReader locla_file=new FileReader(file); BufferedReader input=new BufferedReader(locla_file); char bb[]=new char[1024]; String []read_all=null; String str=null; int len=-1; List<String> reads=new ArrayList<String>(); while((len=input.read(bb))!=-1){ String read=new String(bb,0,len); reads.add(read); } StringHandle stringHandle=new StringHandle(); str=stringHandle.ListToString(reads); read_all=str.split("\\r?\\n"); return read_all; }
简单学习了Ajax技术:https://www.bilibili.com/video/av29885002 24和25集
学习Echart:https://www.bilibili.com/video/av73796938
3,遇到的问题:
1,今天爬取信件数据时又发现包含爬取字段的div的属性值,有的网页有空格,有的网页没有空格;最后我爬取每个数据时都加了判断,当用一个方式无法爬取数据则用第二个方式。
2,今天读取文件截取每条信件的内容,结果之前保存时是用$$分割的,结果用split函数时不能有效分割,然后试了多个字符后最终用换行进行分割;效果很好,还有有些信件的详细内容字数真多,我存入时mysql的varchar的长度设置了1000都不够,也认识到了varchar可以存储的数据长度之大。
4,明天计划:继续学习Echart,将mysql的数据分析并用图表展示