Java 从网页抽取数据 存入数据库

Java 从网页抽取数据 存入数据库,第1张

台风的编号和名称直接在源码中有,但时间和地理位置我只能跟踪到
function totf(tfbh){
locationhref( "Typhoonaspxid="+tfbh);
}
数据需要从aspx中拿到的,应该是存放到数据库的,页面上是拿不到的
我认为可以通过循环模拟发送请求Typhoonaspxid="+XXX,然后通过解析response包的方式可以获得详细的信息
下面一个页面是讲模拟发送请求的
http://tidus2005javaeyecom/blog/195544
希望对你有帮助
我写了一段获得一组数据的代码
//get Typhoon content by param
public static String getTyphoon(String param) {
URL url = null;
try {
url = new URL(param);
} catch (MalformedURLException e) {
eprintStackTrace();
}
HttpURLConnection connection = null;
InputStream is = null;
try {
connection = (HttpURLConnection) urlopenConnection();
is = connectiongetInputStream();
} catch (IOException e) {
eprintStackTrace();
}
BufferedInputStream bis = new BufferedInputStream(is);

int len = 0;
byte[] buf_all = new byte[0];
try {
while (true) {
byte[] buf1 = new byte[4096];
byte[] buf2 = buf_all;
len = bisread(buf1);
if(len <= 0){
break;
}
buf_all = new byte[len+buf2length];
Systemarraycopy(buf2, 0, buf_all, 0, buf2length);
Systemarraycopy(buf1, 0, buf_all, buf2length, len);
}
} catch (IOException e) {
eprintStackTrace();
}
String content = null;
try {
content = new String(buf_all, "utf-8");
} catch (UnsupportedEncodingException e) {
eprintStackTrace();
}
int startIndex = contentindexOf("var ary0=")+9;
content = contentsubstring(startIndex);
int endIndex = contentindexOf("var aryyb0=");
content = contentsubstring(0, endIndex);
return content;
}
得到的结果是这样的:
[['200906','2009-07-19 20:00:00','238','1096','','15','','','260','','','54440','','莫拉菲','Molave','7'],
['200906','2009-07-19 15:00:00','235','111','993','15','25','西北西','260','','','54439','','莫拉菲','Molave','7'],
['200906','2009-07-19 14:00:00','233','1112','','18','','','260','','','54438','','莫拉菲','Molave','8'],
['200906','2009-07-19 13:00:00','233','1115','990','18','25','西北西','260','','','54437','','莫拉菲','Molave','8'],
['200906','2009-07-19 12:00:00','232','1118','990','18','25','西北西','260','','','54436','','莫拉菲','Molave','8'],
['200906','2009-07-19 11:00:00','232','1121','987','18','25','西北西','260','','','54435','','莫拉菲','Molave','8'],
['200906','2009-07-19 10:00:00','232','1124','987','18','25','西北西','260','','','54434','','莫拉菲','Molave','8'],
['200906','2009-07-19 09:00:00','23','1126','987','20','25','西北西','260','','','54433','','莫拉菲','Molave','8'],
['200906','2009-07-19 08:00:00','229','1129','987','20','','','260','','','54432','','莫拉菲','Molave','8'],
['200906','2009-07-19 07:00:00','229','1132','985','23','25','西北西','260','','','54431','','莫拉菲','Molave','9'],
['200906','2009-07-19 06:00:00','228','1134','982','25','25','西北西','260','','','54430','','莫拉菲','Molave','10'],
['200906','2009-07-19 05:00:00','227','1137','980','28','25','西北西','260','','','54429','','莫拉菲','Molave','10'],
['200906','2009-07-19 04:00:00','227','114','975','30','25','西北西','260','','','54428','','莫拉菲','Molave','11'],
['200906','2009-07-19 03:00:00','227','1142','975','33','25','西北偏西','260','80','','54426','','莫拉菲','Molave','12'],
['200906','2009-07-19 02:00:00','226','1145','','35','','','260','80','','54425','','莫拉菲','Molave','12'],
['200906','2009-07-19 01:00:00','225','1145','970','35','28','西北西','260','80','','54424','','莫拉菲','Molave','12'],
['200906','2009-07-19 00:00:00','225','1148','965','38','28','西北西','260','80','','54423','','莫拉菲','Molave','13'],
['200906','2009-07-18 23:00:00','224','1151','','38','','','260','80','','54422','','莫拉菲','Molave','13'],
['200906','2009-07-18 22:00:00','223','1155','965','38','25','西北西','260','80','','54421','','莫拉菲','Molave','13'],
['200906','2009-07-18 21:00:00','222','1157','965','38','25','西北西','260','80','','54420','','莫拉菲','Molave','13'],
['200906','2009-07-18 20:00:00','222','116','','35','','','260','80','','54419','','莫拉菲','Molave','12'],
['200906','2009-07-18 19:00:00','222','1162','970','35','25','西北偏西','260','80','','54418','','莫拉菲','Molave','12'],
['200906','2009-07-18 18:00:00','221','1165','970','35','25','西北偏西','260','80','','54417','','莫拉菲','Molave','12'],
['200906','2009-07-18 17:00:00','22','1167','970','35','25','西北西','260','80','','54416','','莫拉菲','Molave','12'],
['200906','2009-07-18 16:00:00','219','1169','970','35','25','西北偏西','260','80','','54415','','莫拉菲','Molave','12'],
['200906','2009-07-18 15:00:00','218','1171','970','35','25','西北偏西','260','80','','54414','','莫拉菲','Molave','12'],
['200906','2009-07-18 14:00:00','217','1172','970','35','25','西北西','260','80','','54413','','莫拉菲','Molave','12'],
['200906','2009-07-18 13:00:00','217','1174','970','35','25','西北西','260','80','','54412','','莫拉菲','Molave','12'],
['200906','2009-07-18 12:00:00','216','1175','975','33','25','西北西','260','80','','54411','','莫拉菲','Molave','12'],
['200906','2009-07-18 11:00:00','216','1177','975','33','25','西北西','260','80','','54410','','莫拉菲','Molave','12'],
['200906','2009-07-18 10:00:00','216','1179','975','33','25','西北西','260','80','','54409','','莫拉菲','Molave','12'],
['200906','2009-07-18 09:00:00','215','1182','975','33','25','西北西','260','80','','54408','','莫拉菲','Molave','12'],
['200906','2009-07-18 08:00:00','214','1183','975','33','25','西北偏西','260','80','','54407','','莫拉菲','Molave','12'],
['200906','2009-07-18 07:00:00','214','1185','975','33','25','西北西','260','80','','54406','','莫拉菲','Molave','12'],
['200906','2009-07-18 06:00:00','213','1187','975','33','25','西北西','260','80','','54405','','莫拉菲','Molave','12'],
['200906','2009-07-18 05:00:00','212','119','975','33','','','260','60','','54404','','莫拉菲','Molave','12'],
['200906','2009-07-18 04:00:00','212','1192','978','30','25','西北西','260','60','','54403','','莫拉菲','Molave','11'],
['200906','2009-07-18 03:00:00','211','1194','978','30','25','西北偏西','260','60','','54402','','莫拉菲','Molave','11'],
['200906','2009-07-18 02:00:00','21','1196','978','30','','','260','60','','54401','','莫拉菲','Molave','11'],
['200906','2009-07-18 01:00:00','21','1201','978','30','25','西北偏西','260','60','','54400','','莫拉菲','Molave','11'],
['200906','2009-07-18 00:00:00','209','1203','978','30','25','西北偏西','260','60','','54399','','莫拉菲','Molave','11'],
['200906','2009-07-17 23:00:00','208','1205','978','30','20','西北偏西','260','60','','54398','','莫拉菲','Molave','11'],
['200906','2009-07-17 22:00:00','207','121','978','30','20','西北偏西','260','60','','54397','','莫拉菲','Molave','11'],
['200906','2009-07-17 21:00:00','207','1212','978','30','20','西北偏西','260','60','','54396','','莫拉菲','Molave','11'],
['200906','2009-07-17 20:00:00','206','1215','978','30','20','西北偏西','260','60','','54395','','莫拉菲','Molave','11'],
['200906','2009-07-17 19:00:00','204','1218','980','28','20','西北西','260','60','','54394','','莫拉菲','Molave','10'],
['200906','2009-07-17 18:00:00','203','1219','980','28','20','西北偏西','260','60','','54393','','莫拉菲','Molave','10'],
['200906','2009-07-17 17:00:00','202','1221','980','28','20','西北偏西','200','50','','54392','','莫拉菲','Molave','10'],
['200906','2009-07-17 14:00:00','195','1227','','25','','','200','50','','54391','','莫拉菲','Molave','10'],
['200906','2009-07-17 11:00:00','189','1233','985','25','15','西北','200','50','','54390','','莫拉菲','Molave','10'],
['200906','2009-07-17 08:00:00','186','1236','994','20','','','100','','','54389','','莫拉菲','Molave','8'],
['200906','2009-07-17 05:00:00','184','1239','996','18','15','西北','100','','','54388','','莫拉菲','Molave','8'],
['200906','2009-07-17 02:00:00','179','1241','996','18','15','西北','50','','','54387','','莫拉菲','Molave','8'],
['200906','2009-07-16 23:00:00','176','1246','996','18','15','西北','','','','54386','','莫拉菲','Molave','8'],
['200906','2009-07-16 20:00:00','174','1247','996','18','','','','','','54385','','莫拉菲','Molave','8']];
再下去字符串的拆分实在是太复杂了,不想写了
使用时只要参数为http://wwwwztf121com/Typhoonaspxid=
id后是台风的代码号,写一个循环就可以了

以上就是关于Java 从网页抽取数据 存入数据库全部的内容,包括:Java 从网页抽取数据 存入数据库、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9389350.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存