Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions dc-backend/src/main/java/api/estimate/EstimateServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,10 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t

/*In use when click change button.
* */
String estiId="";
try {
estiId = pathParam[2];
System.out.println("estiId is "+estiId);
Logger.getLogger("estiId ",estiId);
}catch (NullPointerException nu){
nu.printStackTrace();
}
/*
* check whether ID is in the estimate table;
* if not,we create one.Then update.

* if in,we directly get.
* */
String[][] IDArray = DBUtil.select("estimate", new String[]{"estiId"});
String estiId = "";
estiId = pathParam[2];
String[]params_estiId={"estiId"};
String[][] IDArray = DBUtil.select("estimate", params_estiId);
HashSet<String> IDset = new HashSet<>();
for (String[] aID : IDArray) {
IDset.add(aID[0]);
Expand All @@ -124,9 +113,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
String[] params = new String[]{
"linksXpath", "contentXpath", "startWord", "walkTimes", "contentLocation", "querySend"
};
String[] conParams = {"estiId"};

String[] conPalues = {estiId};
String[][] estiData = DBUtil.select("estimate", params, conParams, conPalues);
String[][] estiData = DBUtil.select("estimate", params, params_estiId, conPalues);

for (int i = 0; i < params.length; i++) {
if (estiData[0][i] != null) {
Expand All @@ -136,7 +125,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}
}

String[][] IDArray1 = DBUtil.select("urlbaseconf", new String[]{"webId"});
String []params_webId={"webId"};
String[][] IDArray1 = DBUtil.select("urlBaseConf", params_webId);
HashSet<String> IDset1 = new HashSet<>();
for (String[] aID : IDArray1) {
IDset1.add(aID[0]);
Expand All @@ -149,7 +139,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t

String[][] urlBaseConfData;
if (IDset1.contains(estiId)) {
urlBaseConfData = DBUtil.select("urlbaseconf", params1, conParams1, conPalues1);
urlBaseConfData = DBUtil.select("urlBaseConf", params1, conParams1, conPalues1);
} else {
urlBaseConfData = new String[1][params1.length];
for (int i = 0; i < params1.length; i++) {
Expand Down
5 changes: 3 additions & 2 deletions dc-backend/src/main/java/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mysqlUserName=root
mysqlPassword=123456
mysqlURL=jdbc:mysql://localhost:3306/webcrawler?characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8

mysqlPassword=ElTo@EW*nIWOt2Tk
mysqlURL=jdbc:mysql://10.24.11.134:3306/webcrawler?characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true

baseWorkDir=/Users/cwc/Desktop/tencent/data-crawling/

Expand Down
21 changes: 16 additions & 5 deletions dc-backend/src/main/java/util/DBUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,22 @@ public static String[][] selectAllTable_data(String table) throws Exception {
}

public static void main(String[] args){
String[] params_value = {"aaaa","prefix"};
String[] params= {"requestName","requestDesc"};
boolean flag = DBUtil.insert("requesttable", params, params_value);
System.out.println("insert or not ?"+flag);

// String[] params_value = {"aaaa","prefix"};
// String[] params= {"requestName","requestDesc"};
// boolean flag = DBUtil.insert("requesttable", params, params_value);
// System.out.println("insert or not ?"+flag);
// String[][] IDArray1 = DBUtil.select("urlBaseconf", new String[]{""});
String[][] IDArray = new String[0][];
try {
IDArray = DBUtil.select("estimate",new String[]{"estiId"});
} catch (Exception e) {
e.printStackTrace();
}
for(int i=0;i<IDArray.length;i++){
for (int j=0;j<IDArray[0].length;j++)
System.out.print(IDArray[i][j]+" ");
System.out.println();
}
}

}
6 changes: 3 additions & 3 deletions dc-backend/src/main/java/util/WebCrawlerDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ private Map<String, Boolean> crawlLinks(String oldLinkHost,
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(2000);
connection.setReadTimeout(2000);
connection.setConnectTimeout(200000);
connection.setReadTimeout(200000);

if (connection.getResponseCode() == 200) {
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStream, "UTF-8"));
String line = "";
Pattern pattern = Pattern
.compile("<a.*?href=[\"']?((https?://)?/?[^\"']+)[\"']?.*?>(.+)</a>");
.compile("<[aA]{1}.*?href=[\"']?((https?://)?/?[^\"']+)[\"']?.*?>(.+)</[aA]{1}>");
Matcher matcher = null;
while (((line = reader.readLine()) != null)&&stopFlag) {
matcher = pattern.matcher(line);
Expand Down
Binary file not shown.