China Naming Network - Ziwei Dou Shu - Java extracts data from web pages and stores it in the database.

Java extracts data from web pages and stores it in the database.

The number and name of the typhoon are directly in the source code, but I can only track the time and geographical location.

Function totf (tfbh) (

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

}

You need to get data from aspx. The data should be stored in the database, but it can't be obtained on the page.

I think we can send the request Typhoon.aspx through loop simulation? Id="+XXX ",and then parse the response package to get detailed information.

The next page is about analog sending requests.

/blog/ 195544

I hope it helps you.

I wrote a piece of code to get a set of data.

//Get typhoon content through parameters.

Common static string gettyphoon (stringparam) (

URL url = null

Try {

Url = new URL (param);

} catch(malformedurexception e){

e . printstacktrace();

}

HttpURLConnection connection = null

InputStream is = null.

Try {

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 = new byte [0];

Try {

while (true) {

Byte[] buf 1 = new byte [4096];

byte[]buf 2 = buf _ all;

len = bis . read(buf 1);

if(len & lt; = 0){

Break;

}

Buf_all = new byte [len+buf2.length];

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

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

}

} catch (IOException e) {

e . printstacktrace();

}

String content = null

Try {

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);

Return content;

}

The result is this:

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

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

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

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

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

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

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

['200906',' 2009-07- 19 09: 00',' 23','12.6',' 987',' 20',' 25',' northwest.

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

['200906',' 2009-07- 19 07: 00: 00',' 22.9','1/3.2',' 985',' 23',' 25'.

['200906',' 2009-07- 19 06: 00: 00',' 22.8','1/3.4',' 982',' 25',' 25'.

['200906',' 2009-07- 19 05: 00',' 22.7','13.7',' 980',' 28',' 25','

['200906',' 2009-07-19 04: 00',' 22.7',' 1 14',' 975',' 30',' 25',.

['200906',' 2009-07- 19 03: 00: 00',' 22.7','1/4.2',' 975',' 33',' 25'.

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

['200906',' 2009-07- 19 0 1: 00',' 22.5',' 1 14.5',' 970',' 35',' 28'

['200906',' 2009-07- 19 00: 00',' 22.5','14.8',' 965',' 38',' 28','

['200906',' 2009-07- 18 23: 00: 00',' 22.4',' 1 15. 1',',' 38',','

['200906',' 2009-07- 18 22: 00: 00',' 22.3',' 1 15.5',' 965',' 38',' 25'.

['200906',' 2009-07- 18 2 1: 00',' 22.2',' 1 15.7',' 965',' 38',' 25'.

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

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

['200906',' 2009-07- 18 18: 00',' 22. 1',' 1 16.5',' 970',' 35'

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

['200906',' 2009-07- 18 16: 00',' 2 1.9',' 1 16.9',' 970',' 35'

['200906',' 2009-07- 18 15: 00',' 2 1.8',' 1 1',' 970'.

['200906',' 2009-07- 18 14: 00',' 2 1.7',' 1 17.2',' 970',' 35'

['200906',' 2009-07- 18 13: 00',' 2 1.7',' 1 17.4',' 970',' 35'

['200906',' 2009-07- 18 12: 00',' 2 1.6',' 1 17.5',' 975',' 33'

['200906',' 2009-07- 18 1 1: 00',' 2 1.6',' 1 17.7',' 975'.

['200906',' 2009-07- 18 10: 00',' 2 1.6',' 1 17.9',' 975',' 33'

['200906',' 2009-07- 18 09: 00: 00',' 2 1.5',' 1 18.2',' 975',' 33',' 25'.

['200906',' 2009-07- 18 08: 00: 00',' 2 1.4',' 1 18.3',' 975',' 33',' 25'.

['200906',' 2009-07- 18 07: 00: 00',' 2 1.4',' 1 18.5',' 975',' 33',' 25'.

['200906',' 2009-07- 18 06: 00: 00',' 2 1.3',' 1 18.7',' 975',' 33',' 25'.

['200906',' 2009-07- 18 05: 00: 00',' 2 1.2',' 1 19',' 975',' 33',','

['200906',' 2009-07- 18 04: 00: 00',' 2 1.2',' 1 19.2',' 978',' 30',' 25'.

['200906',' 2009-07- 18 03: 00: 00',' 2 1. 1',' 1 19.4',' 978',' 30'

['200906',' 2009-07- 18 02: 00: 00',' 2 1',' 1 19.6',' 978',' 30',','

['200906',' 2009-07- 18 0 1: 00',' 2 1',' 120. 1',' 978',' 30'.

['200906',' 2009-07- 18 00: 00',' 20.9',' 120.3',' 978',' 30',' 25',' west-northwest',

['200906',' 2009-07- 17 23: 00: 00',' 20.8',' 120.5',' 978',' 30',' 20',' west-northwest.

['200906',' 2009-07- 17 22: 00: 00',' 20.7',' 12 1',' 978',' 30',' 20'.

['200906',' 2009-07- 17 2 1: 00',' 20.7',' 12 1.2',' 978',' 30',' 20'.

['200906',' 2009-07- 17 20: 00',' 20.6',' 12 1.5',' 978',' 30',' 20',.

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

['200906',' 2009-07- 17 18: 00',' 20.3',' 12 1.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 1 1: 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',''

Disassembling strings is too complicated, so I don't want to write.

As long as the parameter is /Typhoon.aspx? id=

After the id is the code name of the typhoon, just write a cycle.