0
我检查了其他链接,但是我找不到解决方案。 我可以连接到353个链接,并在大约7分钟内抓取我需要的数据。我需要把时间缩短到不到1分钟。用BufferedWriter在Java中获取353个网页的更快方法
我在下面列入了我的代码。
URL urlChartLink;
URLConnection urlconn;
try {
Class.forName(driver).newInstance();
Connection mysqlconn = DriverManager.getConnection(url + dbName, userName, password);
Statement st1 = mysqlconn.createStatement();
Connection mysqlconn2 = DriverManager.getConnection(url + dbName, userName, password);
ResultSet rs1 = st1.executeQuery(strSQL);
while (rs1.next())
{
sElementID = rs1.getString(1);
sSymbol = rs1.getString(2);
sChartLink = rs1.getString(3);
urlChartLink = new URL(sChartLink);
urlconn = urlChartLink.openConnection();
urlconn.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
sCurrentPrice = "";
sPriceChange = "";
try {
BufferedReader in = new BufferedReader(new InputStreamReader(urlconn.getInputStream(), "UTF-8"));
String currentLine;
int iLine = 0;
while ((currentLine = in.readLine()) != null) {
//Get data from page
iLine += 1;
}
in.close();
} catch (IOException e) {
}
st1.close();
mysqlconn.close();
mysqlconn2.close();
}
我试过了没有URLConnection,但我得到了403错误。
如果有人能给我一个更好的解决方案,这将是伟大的!
Eddi Rae
不知道时机,但我喜欢用jSoup进行网页抓取。 –