|
|
package Reptile;
|
|
|
|
|
|
import java.io.BufferedWriter;
|
|
|
import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.sql.Statement;
|
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
import com.mysql.cj.jdbc.result.ResultSetMetaData;
|
|
|
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
public class test {
|
|
|
public static void main(String[] args) {
|
|
|
/*
|
|
|
* 在这里调用dochck方法,传参症状
|
|
|
* */
|
|
|
|
|
|
}
|
|
|
public static void dochck(String keyworString) {
|
|
|
DBUtil.Connection();
|
|
|
String urlString = "http://www.tcmkb.cn/kg/health2_service.php?keywords="+keyworString;
|
|
|
JSONObject jsonObject = null;
|
|
|
try {
|
|
|
jsonObject = ReadUrlUtil.readJsonFromUrl(urlString);
|
|
|
} catch (MalformedURLException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
} catch (IOException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
int deseaseid = DBUtil.finddid(keyworString);
|
|
|
|
|
|
// 已经能够得出json数据
|
|
|
// 能够分理处nodes属性的内容d,id,label,type
|
|
|
JSONArray datasArray = jsonObject.getJSONObject("data").getJSONArray("nodes");
|
|
|
for(int i=1;i<datasArray.size();i++) {
|
|
|
//外部循环可以获取每一种养生方法
|
|
|
// 每个数组有type,id,label,description
|
|
|
JSONObject jo = (JSONObject) datasArray.get(i);
|
|
|
String nameString = jo.getString("id");//养生方法名
|
|
|
// String typeString = jo.getString("type");//关系:养生方法
|
|
|
// String labelString = jo.getString("label");//标签
|
|
|
String describtionString = jo.getString("description");
|
|
|
|
|
|
// 先将病症和养生方法关系建立起来
|
|
|
int yid = DBUtil.findyid(nameString); //这个返回要么是新的id,要么是已经存在的yid,如果已经存在的没必要重复插入这个养生方法,但是不管是不是新的,did和yid的关系还是要建立
|
|
|
|
|
|
DBUtil.ytod(yid, deseaseid);
|
|
|
DBUtil.dtoy(deseaseid, yid);
|
|
|
|
|
|
|
|
|
if(DBUtil.isnewyid) {
|
|
|
//不存在就要先插入这个养生方法,然后写入id,并将其他信息搞进去。
|
|
|
|
|
|
// 接下来解析description:就是有关某个养生方法的信息,这些养生方法信息要插入到yangsheng表里
|
|
|
StringBuilder sqllindex = new StringBuilder("id,mname");
|
|
|
StringBuilder sqlvalue = new StringBuilder(yid+",'"+nameString+"'");
|
|
|
Document document = Jsoup.parse(describtionString);
|
|
|
Elements elements = document.select("p:has(font)");//该药的所有的p标签
|
|
|
for(Element element:elements) {
|
|
|
String element2 = element.select("font:has(strong)").first().text();//获取字段名
|
|
|
String eleString = element.text();
|
|
|
String valueString = eleString.substring(element2.length(), eleString.length());
|
|
|
if(valueString.startsWith(": ")) valueString = valueString.substring(2);
|
|
|
//valueString是字段对应的值
|
|
|
if(perfix.indexchinese.contains(element2)) {
|
|
|
//如果包含了,那么就包含进去
|
|
|
sqllindex = sqllindex.append(","+perfix.indexenglish.get(perfix.indexchinese.indexOf(element2)));
|
|
|
sqlvalue = sqlvalue.append(",'"+valueString+"'");
|
|
|
}//不包含就不要管了
|
|
|
}
|
|
|
//插入
|
|
|
DBUtil.insertintoY(sqllindex.toString(), sqlvalue.toString());
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
System.out.println("end");
|
|
|
DBUtil.close();
|
|
|
|
|
|
}
|
|
|
}
|