當前位置:歷史故事大全網 - 歷史上的今天 - Java從網頁中提取數據並存儲在數據庫中。

Java從網頁中提取數據並存儲在數據庫中。

臺風的編號和名稱直接在源代碼裏,但我只能追蹤時間和地理位置。

功能totf(tfbh){

location.href( "Typhoon.aspx?id = "+tfbh);

}

需要從aspx中獲取數據,數據應該存儲在數據庫中,但是在頁面上無法獲取。

我覺得可以通過循環模擬發送請求Typhoon.aspx?Id="+XXX ",然後解析響應包就可以得到詳細的信息。

下壹頁是關於模擬發送請求。

/blog/195544

希望對妳有幫助。

我寫了壹段代碼來獲取壹組數據。

//通過參數獲取臺風內容

公共靜態字符串getTyphoon(String param) {

URL url = null

嘗試{

url =新URL(param);

} catch(malformedurexception e){

e . printstacktrace();

}

HttpURLConnection連接= null

InputStream為= null

嘗試{

connection =(http urlconnection)URL . open connection();

is = connection . getinputstream();

} catch (IOException e) {

e . printstacktrace();

}

BufferedInputStream bis = new BufferedInputStream(is);

int len = 0;

byte[] buf_all =新字節[0];

嘗試{

while (true) {

byte[] buf1 =新字節[4096];

byte[]buf 2 = buf _ all;

len = bis . read(buf 1);

if(len & lt;= 0){

打破;

}

buf_all =新字節[len+buf 2 . length];

System.arraycopy(buf2,0,buf_all,0,buf 2 . length);

System.arraycopy(buf1,0,buf_all,buf2.length,len);

}

} catch (IOException e) {

e . printstacktrace();

}

字符串內容= null

嘗試{

content = new String(buf_all,“utf-8”);

} catch(UnsupportedEncodingException e){

e . printstacktrace();

}

int startIndex = content . index of(" var ary 0 = ")+9;

content = content . substring(startIndex);

int end index = content . index of(" var aryb 0 = ");

content = content.substring(0,end index);

返回內容;

}

結果是這樣的:

[['200906',' 2009-07-19 20: 00: 00',' 23.8',' 109.6','',' 15','','

['200906',' 2009-07-19 15: 00',' 23.5',' 11',' 993',' 65438'.

['200906',' 2009-07-19 14: 00',' 23.3',' 11.2','',' 65438+

['200906',' 2009-07-19 13: 00',' 23.3',' 11.5',' 990',' 65438'.

['200906',' 2009-07-19 12: 00',' 23.2',' 11.8',' 990',' 65438'.

['200906',' 2009-07-19 11: 00',' 23.2',' 11',' 987'.

['200906',' 2009-07-19 10: 00',' 23.2',' 112.4',' 987',' 18'.

['200906 ',' 2009-07-19 09: 00 ',' 23 ',' 112.6 ',' 987 ',' 20 ',' 25 ','西北。

['200906',' 2009-07-19 08: 00: 00',' 22.9',' 112.9',' 987',' 20','',''

['200906 ',' 2009-07-19 07: 00: 00 ',' 22.9 ',' 113.2 ',' 985 ',' 23 ',' 25 ','西北'

['200906 ',' 2009-07-19 06: 00: 00 ',' 22.8 ',' 113.4 ',' 982 ',' 25 ',' 25 ','西北'

['200906 ',' 2009-07-19 05: 00 ',' 22.7 ',' 113.7 ',' 980 ',' 28 ',' 25 ','西北。

['200906 ',' 2009-07-19 04: 00: 00 ',' 22.7 ',' 114 ',' 975 ',' 30 ',' 25 ','西北。

['200906 ',' 2009-07-19 03: 00: 00 ',' 22.7 ',' 114.2 ',' 975 ',' 33 ',' 25 ','西北。

['200906',' 2009-07-19 02: 00: 00',' 22.6',' 114.5',',' 35',','',' 26438.

['200906',' 2009-07-19 01: 00',' 22.5',' 114.5',' 970',' 35',' 28'

['200906 ',' 2009-07-19 00: 00 ',' 22.5 ',' 114.8 ',' 965 ',' 38 ',' 28 ','西北。

['200906',' 2009-07-18 23: 00: 00',' 22.4',' 115.1',',' 38',','

['200906 ',' 2009-07-18 22: 00: 00 ',' 22.3 ',' 115.5 ',' 965 ',' 38 ',' 25 ','西北。

['200906',' 2009-07-18 21: 00',' 22.2',' 115.7',' 965',' 38',' 25'.

['200906',' 2009-07-18 20: 00',' 22.2',' 116','',' 35','',' 260'.

['200906',' 2009-07-18 19: 00',' 22.2',' 116.2',' 970',' 35',' 25'.

['200906',' 2009-07-18 18: 00',' 22.1',' 116.5',' 970',' 35'

['200906',' 2009-07-18 17: 00',' 22',' 116.7',' 970',' 35',' 25'.

['200906',' 2009-07-18 16: 00',' 21.9',' 116.9',' 970',' 35'

['200906',' 2009-07-18 15: 00',' 21.8',' 11',' 970'.

['200906',' 2009-07-18 14: 00',' 21.7',' 117.2',' 970',' 35'

['200906',' 2009-07-18 13: 00',' 21.7',' 117.4',' 970',' 35'

['200906',' 2009-07-18 12: 00',' 21.6',' 117.5',' 975',' 33'

['200906',' 2009-07-18 11: 00',' 21.6',' 117.7',' 975'.

['200906',' 2009-07-18 10: 00',' 21.6',' 117.9',' 975',' 33'

['200906',' 2009-07-18 09: 00: 00',' 21.5',' 118.2',' 975',' 33',' 25'.

['200906',' 2009-07-18 08: 00: 00',' 21.4',' 118.3',' 975',' 33',' 25'.

['200906',' 2009-07-18 07: 00: 00',' 21.4',' 118.5',' 975',' 33',' 25'.

['200906',' 2009-07-18 06: 00: 00',' 21.3',' 118.7',' 975',' 33',' 25'.

['200906',' 2009-07-18 05: 00: 00',' 21.2',' 119',' 975',' 33',','

['200906',' 2009-07-18 04: 00: 00',' 21.2',' 119.2',' 978',' 30',' 25'.

['200906',' 2009-07-18 03: 00: 00',' 21.1',' 119.4',' 978',' 30'

['200906',' 2009-07-18 02: 00: 00',' 21',' 119.6',' 978',' 30',','

['200906',' 2009-07-18 01: 00',' 21',' 120.1',' 978',' 30'.

['200906 ',' 2009-07-18 00: 00 ',' 20.9 ',' 120.3 ',' 978 ',' 30 ',' 25 ','西-西北','

['200906 ',' 2009-07-17 23: 00: 00 ',' 20.8 ',' 120.5 ',' 978 ',' 30 ',' 20 ','西-西北','

['200906 ',' 2009-07-17 22: 00: 00 ',' 20.7 ',' 121 ',' 978 ',' 30 ',' 20 ','西-西北。

['200906',' 2009-07-17 21: 00',' 20.7',' 121.2',' 978',' 30',' 20'.

['200906 ',' 2009-07-17 20: 00 ',' 20.6 ',' 121.5 ',' 978 ',' 30 ',' 20 ','西北。

['200906',' 2009-07-17 19: 00',' 20.4',' 121.8',' 980',' 28',' 20'.

['200906',' 2009-07-17 18: 00',' 20.3',' 121.9',' 980',' 28',' 20'.

['200906',' 2009-07-17 17: 00',' 20.2',' 122.1',' 980',' 28',' 20'

['200906',' 2009-07-17 14: 00',' 19.5',' 122.7','',' 25','','

['200906',' 2009-07-17 11: 00',' 18.9',' 123.3',' 985',' 25'

['200906',' 2009-07-17 08: 00: 00',' 18.6',' 123.6',' 994',' 20','','

['200906',' 2009-07-17 05: 00: 00',' 18.4',' 123.9',' 996',' 18',' 65438.

['200906',' 2009-07-17 02: 00: 00',' 17.9',' 124.1',' 996',' 18'

['200906',' 2009-07-16 23: 00: 00',' 17.6',' 124.6',' 996',' 18',' 65438.

['200906',' 2009-07-16 20: 00: 00',' 17.4',' 124.7',' 996',' 18',''

拆串太復雜了,不想寫了。

只要參數是/Typhoon.aspx?id=

id後面是臺風的代號,寫個周期就行了。

  • 上一篇:浙江醫院的歷史沿革
  • 下一篇:紅谷米的功效與作用,紅谷米的功效與禁忌。
  • copyright 2024歷史故事大全網