文件名称:jsoup解析html
文件大小:7KB
文件格式:JAVA
更新时间:2018-05-25 07:47:12
jsoup html
用jsoup解析html的实例// 将dt中的内容同数据库中的数据进行比较 for (int n = 1; n <= data.getColumnCount(); n++) { if (dtInformation2.contains(data.getColumnName(n))) {// .equals(data.getColumnName(n)) // 提取dd下面的内容 String nowColumnName = data.getColumnName(n); Element ddP0 = ddInformation.get(i); ddP0.select("table").remove(); if(ddP0.html().contains("'") || ddP0.html().contains("")){ String ddP1 = ddP0.text().replaceAll("'", "(单引号)"); String ddP2 = ddP1.replaceAll("", " "); String ddP3 = ddP2.replaceAll(""," "); value = ddP3; }else{ value = ddP0.text(); } // System.out.print(value); if( n == 2){ insertAndUpdateSql = "INSERT INTO dxycontentcnOne (" + nowColumnName + ")" + "VALUE('" + value + "')"; // 插入数据的sql语句; }else { updateCloumnIdSql = "select id from dxycontentcnOne order by id desc limit 0,1"; java.sql.PreparedStatement stmtId = conn.prepareStatement(updateCloumnIdSql); ResultSet rs1 = stmtId.executeQuery();// 得到结果集 while(rs1.next()){ idNum = rs1.getInt(1); insertAndUpdateSql = "UPDATE `dxycontentcnOne` set `"+nowColumnName+"` = '"+value+"' where (`id` = '"+idNum+"') ;"; } } stmt1 = (Statement) conn.createStatement(); // 创建用于执行静态sql语句的Statement对象 int count = stmt1.executeUpdate(insertAndUpdateSql); // 执行插入操作的sql语句,并返回插入数据的个数 System.out.println("插入成功1"); }else{ } }