关于有道翻译接口的爬取
目录结构
–TranSpider.java (用于主要的爬取相关
–TranBean.java (爬取之后的存储结构
–Test.java (用于测试
TranBean.java相关
package com.lilutong.trans;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class TransBean {
String word=null;
public Timestamp timestamp=null;
List<String> trans=null;
public TransBean() {
word="";
String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());//将时间格式转换成符合Timestamp要求的格式.
timestamp=Timestamp.valueOf(nowTime);
trans=new ArrayList<String>();
}
public void addTrans(String tran) {
this.trans.add(tran);
}
//以下为自动生成的get+set+tostring
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
public List<String> getTrans() {
return trans;
}
public void setTrans(List<String> trans) {
this.trans = trans;
}
public void addTrans(String tran) {
this.trans.add(tran);
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "TransBean [word=" + word + ", timestamp=" + timestamp + ", trans=" + trans + "]";
}
}
- word—-前端传输的英文
- timestramp —-插入数据库的时间 (方便排序
- List —-单词的翻译组
*TranSpider.java相关
package com.lilutong.trans;
import java.io.*;
import java.net.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.Header;
import org.a