commit f7abaef8d244ec7311c5111d321d7428f6953135
Author: ziyonghong <1131002466@qq.com>
Date: Wed Jan 1 21:24:18 2020 +0800
爬取数据
diff --git a/chinese/.classpath b/chinese/.classpath
new file mode 100644
index 0000000..584a118
--- /dev/null
+++ b/chinese/.classpath
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/chinese/.project b/chinese/.project
new file mode 100644
index 0000000..c98494d
--- /dev/null
+++ b/chinese/.project
@@ -0,0 +1,23 @@
+
+
+ chinese
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/chinese/.settings/org.eclipse.core.resources.prefs b/chinese/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..4c28b1a
--- /dev/null
+++ b/chinese/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding/=UTF-8
diff --git a/chinese/.settings/org.eclipse.jdt.core.prefs b/chinese/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..e029c71
--- /dev/null
+++ b/chinese/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/chinese/.settings/org.eclipse.m2e.core.prefs b/chinese/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..14b697b
--- /dev/null
+++ b/chinese/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/chinese/pom.xml b/chinese/pom.xml
new file mode 100644
index 0000000..4a095e9
--- /dev/null
+++ b/chinese/pom.xml
@@ -0,0 +1,30 @@
+
+ 4.0.0
+
+ chinesemedicine
+ chinese
+ 0.0.1-SNAPSHOT
+ jar
+
+ chinese
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ org.jsoup
+ jsoup
+ 1.8.3
+
+
+
diff --git a/chinese/src/main/java/Reptile/DBUtil.java b/chinese/src/main/java/Reptile/DBUtil.java
new file mode 100644
index 0000000..f647290
--- /dev/null
+++ b/chinese/src/main/java/Reptile/DBUtil.java
@@ -0,0 +1,150 @@
+package Reptile;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class DBUtil {
+ public static String driverString = "com.mysql.cj.jdbc.Driver";
+ public static String sqlurl = "jdbc:mysql://114.55.37.70:3306/graph";
+
+ public static Connection conn = null;//连接对象
+ public static Statement stat = null;//执行对象
+ public static boolean isnewyid = true;
+ //建立连接
+ public static void Connection() {
+ try {
+ Class.forName(driverString);
+ } catch (ClassNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ try {
+ conn = DriverManager.getConnection(sqlurl, "root", "XBxb0525@");
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ try {
+ stat = conn.createStatement();
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+ //返回desease的did,如果已经存在了,就返回did,不存在就返回下一个
+ public static int finddid(String dname) {
+ String sqlString = "select id from desease where dname="+dname;
+ ResultSet resultSet = null;
+ try {
+ resultSet = stat.executeQuery(sqlString);
+ resultSet.next();
+ return resultSet.getInt(1);
+ } catch (SQLException e) {
+
+// 空,这个病没有存在,将其插入到里面
+
+ int did = countTable("desease")+1;
+ sqlString = "insert into desease values("+did+",'"+dname+"');";//插入这个疾病
+ System.out.println(sqlString);
+ try {
+ stat.executeUpdate(sqlString);
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }//执行语句
+ return did;
+ // TODO Auto-generated catch block
+ }
+ }
+
+ //返回药的yid,如果已经存在了,就返回yid,不存在就返回下一个
+ public static int findyid(String mname) {
+ String sqlString = "select id from yangsheng where mname="+mname;
+ ResultSet resultSet = null;
+ try {
+ resultSet = stat.executeQuery(sqlString);
+ isnewyid = false;
+ resultSet.next();
+ return resultSet.getInt(1);
+
+ } catch (SQLException e) {
+
+// 为空,暂时为它新创建一个id
+
+ isnewyid = true;
+ return countTable("yangsheng")+1;
+ }
+ }
+
+ public static int insertintoY(String index,String values) {
+ String sqlString = "insert into yangsheng("+index+") values("+values+");";
+ System.out.println(sqlString);
+ try {
+ return stat.executeUpdate(sqlString);
+
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ //插入关系表,dtoy
+ public static void dtoy(int did,int yid) {
+ //did是疾病的id,yid是养生方法id
+ String sqlString = "insert into dtoy values("+did+","+yid+");";
+ try {
+ stat.executeUpdate(sqlString);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ System.out.println("dtoy插入数据失败");
+ e.printStackTrace();
+ }
+ }
+ //插入关系,ytod
+ public static void ytod(int yid,int did) {
+ String sqlString = "insert into ytod values("+yid+","+did+");";
+ try {
+ stat.executeUpdate(sqlString);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ //获取某个表的个数
+ public static int countTable(String tablename) {
+ String sqlString = "select count(*) from "+tablename+";";
+ ResultSet resultSet = null;
+ try {
+ resultSet = stat.executeQuery(sqlString);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try {
+ if(resultSet.next()) return resultSet.getInt(1);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ //关闭数据库连接
+ public static void close() {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+
+}
diff --git a/chinese/src/main/java/Reptile/ReadUrlUtil.java b/chinese/src/main/java/Reptile/ReadUrlUtil.java
new file mode 100644
index 0000000..8e7875f
--- /dev/null
+++ b/chinese/src/main/java/Reptile/ReadUrlUtil.java
@@ -0,0 +1,37 @@
+package Reptile;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.Charset;
+
+import javax.naming.ldap.Rdn;
+
+import net.sf.json.JSONObject;
+
+public class ReadUrlUtil {
+ public static JSONObject readJsonFromUrl(String urlString) throws MalformedURLException, IOException {
+ InputStream iStream = new URL(urlString).openStream();
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(iStream, Charset.forName("UTF-8")));
+ StringBuilder sBuilder = new StringBuilder();
+ int cp;
+ while((cp = reader.read())!=-1) {
+ sBuilder.append((char)cp);
+
+ }
+ String jsonText = sBuilder.toString();
+ JSONObject jsonObject = JSONObject.fromObject(jsonText);
+ return jsonObject;
+ } catch (Exception e) {
+ // TODO: handle exception
+ }finally {
+ iStream.close();
+ }
+ return null;
+
+ }
+}
diff --git a/chinese/src/main/java/Reptile/perfix.java b/chinese/src/main/java/Reptile/perfix.java
new file mode 100644
index 0000000..de30a28
--- /dev/null
+++ b/chinese/src/main/java/Reptile/perfix.java
@@ -0,0 +1,23 @@
+package Reptile;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class perfix {
+ /*
+ *
+名字:name
+作用:function
+操作方法:operation
+疾病disease
+证候:syndromes
+部位:position
+症状symptom
+备注Remarks
+禁忌:taboo
+
+ * */
+ public static ArrayList indexchinese = new ArrayList(Arrays.asList("名字","作用","操作方法","疾病","证候","部位","症状","备注","禁忌"));
+ public static ArrayList indexenglish = new ArrayList(Arrays.asList("mname","mfunction","moperation","mdisease","msyndromes","mposition","msymptom","mremarks","mtaboo"));
+
+}
diff --git a/chinese/src/main/java/Reptile/text.java b/chinese/src/main/java/Reptile/text.java
new file mode 100644
index 0000000..fd05f2c
--- /dev/null
+++ b/chinese/src/main/java/Reptile/text.java
@@ -0,0 +1,97 @@
+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 text {
+ 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