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

我想从这个网站抽取网页数据http://www.wztf121.com/,主要是将该页面下部分的台风数据抽取出来,需要获取台风编号,名称,时间,地理位置等,也即是网页右下... 我想从这个网站抽取网页数据http://www.wztf121.com/,主要是将该页面下部分的台风数据抽取出来,需要获取台风编号,名称,时间,地理位置等,也即是网页右下角的表格数据,之后将其存入数据库。望高手指点一二。最好能有完整的代码,用Java写,谢谢各位。
谢谢herogxo和13s13的回答,我想就13s的回答把问题补充一下:当点击左下角表格里的某条记录时,页面会更新,此时右键--查看源文件就能看到诸如:var ary0=[['200906','2009-07-19 20:00:00','23.8','109.6','','15','','','260','','','54440','','莫拉菲','Molave','7'],
['200906','2009-07-19 15:00:00','23.5','111','993','15','25','西北西','260','','','54439','','莫拉菲','Molave','7'],
['200906','2009-07-19 14:00:00','23.3','111.2','','18','','','260','','','54438','','莫拉菲','Molave','8'],
['200906','2009-07-19 13:00:00','23.3','111.5','990','18','25','西北西','260','','','54437','','莫拉菲','Molave','8'],
这样的信息,每个方括号里都包含了我需要的信息,也包括地理位置。我想做的是:
1:怎么样获取这些源文件,因为在页面需要点击
2:获取之后如何解析它,并按页面右下侧表格的形式存入数据库
说白了,就是想获取该网页的一点台风信息,正好我能用到这些信息 谢谢

非常感谢13s13的回答,由于本人新手,不知从何下手,不知13s13能否把向页面发送请求,直至最终获取源文件的完整代码给写下来,谢谢。qiao_shun@163.com
展开
 我来答
13s13
2009-07-30 · 超过23用户采纳过TA的回答
知道答主
回答量:58
采纳率:0%
帮助的人:65.8万
展开全部
台风的编号和名称直接在源码中有,但时间和地理位置我只能跟踪到
function totf(tfbh){
location.href( "Typhoon.aspx?id="+tfbh);
}
数据需要从aspx中拿到的,应该是存放到数据库的,页面上是拿不到的

我认为可以通过循环模拟发送请求Typhoon.aspx?id="+XXX,然后通过解析response包的方式可以获得详细的信息

下面一个页面是讲模拟发送请求的
http://tidus2005.javaeye.com/blog/195544
希望对你有帮助

我写了一段获得一组数据的代码

//get Typhoon content by param
public static String getTyphoon(String param) {
URL url = null;
try {
url = new URL(param);
} catch (MalformedURLException e) {
e.printStackTrace();
}

HttpURLConnection connection = null;
InputStream is = null;
try {
connection = (HttpURLConnection) url.openConnection();
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[] buf1 = new byte[4096];
byte[] buf2 = buf_all;
len = bis.read(buf1);
if(len <= 0){
break;
}
buf_all = new byte[len+buf2.length];
System.arraycopy(buf2, 0, buf_all, 0, buf2.length);
System.arraycopy(buf1, 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.indexOf("var ary0=")+9;
content = content.substring(startIndex);
int endIndex = content.indexOf("var aryyb0=");
content = content.substring(0, endIndex);

return content;
}

得到的结果是这样的:
[['200906','2009-07-19 20:00:00','23.8','109.6','','15','','','260','','','54440','','莫拉菲','Molave','7'],
['200906','2009-07-19 15:00:00','23.5','111','993','15','25','西北西','260','','','54439','','莫拉菲','Molave','7'],
['200906','2009-07-19 14:00:00','23.3','111.2','','18','','','260','','','54438','','莫拉菲','Molave','8'],
['200906','2009-07-19 13:00:00','23.3','111.5','990','18','25','西北西','260','','','54437','','莫拉菲','Molave','8'],
['200906','2009-07-19 12:00:00','23.2','111.8','990','18','25','西北西','260','','','54436','','莫拉菲','Molave','8'],
['200906','2009-07-19 11:00:00','23.2','112.1','987','18','25','西北西','260','','','54435','','莫拉菲','Molave','8'],
['200906','2009-07-19 10:00:00','23.2','112.4','987','18','25','西北西','260','','','54434','','莫拉菲','Molave','8'],
['200906','2009-07-19 09:00:00','23','112.6','987','20','25','西北西','260','','','54433','','莫拉菲','Molave','8'],
['200906','2009-07-19 08:00:00','22.9','112.9','987','20','','','260','','','54432','','莫拉菲','Molave','8'],
['200906','2009-07-19 07:00:00','22.9','113.2','985','23','25','西北西','260','','','54431','','莫拉菲','Molave','9'],
['200906','2009-07-19 06:00:00','22.8','113.4','982','25','25','西北西','260','','','54430','','莫拉菲','Molave','10'],
['200906','2009-07-19 05:00:00','22.7','113.7','980','28','25','西北西','260','','','54429','','莫拉菲','Molave','10'],
['200906','2009-07-19 04:00:00','22.7','114','975','30','25','西北西','260','','','54428','','莫拉菲','Molave','11'],
['200906','2009-07-19 03:00:00','22.7','114.2','975','33','25','西北偏西','260','80','','54426','','莫拉菲','Molave','12'],
['200906','2009-07-19 02:00:00','22.6','114.5','','35','','','260','80','','54425','','莫拉菲','Molave','12'],
['200906','2009-07-19 01:00:00','22.5','114.5','970','35','28','西北西','260','80','','54424','','莫拉菲','Molave','12'],
['200906','2009-07-19 00:00:00','22.5','114.8','965','38','28','西北西','260','80','','54423','','莫拉菲','Molave','13'],
['200906','2009-07-18 23:00:00','22.4','115.1','','38','','','260','80','','54422','','莫拉菲','Molave','13'],
['200906','2009-07-18 22:00:00','22.3','115.5','965','38','25','西北西','260','80','','54421','','莫拉菲','Molave','13'],
['200906','2009-07-18 21:00:00','22.2','115.7','965','38','25','西北西','260','80','','54420','','莫拉菲','Molave','13'],
['200906','2009-07-18 20:00:00','22.2','116','','35','','','260','80','','54419','','莫拉菲','Molave','12'],
['200906','2009-07-18 19:00:00','22.2','116.2','970','35','25','西北偏西','260','80','','54418','','莫拉菲','Molave','12'],
['200906','2009-07-18 18:00:00','22.1','116.5','970','35','25','西北偏西','260','80','','54417','','莫拉菲','Molave','12'],
['200906','2009-07-18 17:00:00','22','116.7','970','35','25','西北西','260','80','','54416','','莫拉菲','Molave','12'],
['200906','2009-07-18 16:00:00','21.9','116.9','970','35','25','西北偏西','260','80','','54415','','莫拉菲','Molave','12'],
['200906','2009-07-18 15:00:00','21.8','117.1','970','35','25','西北偏西','260','80','','54414','','莫拉菲','Molave','12'],
['200906','2009-07-18 14:00:00','21.7','117.2','970','35','25','西北西','260','80','','54413','','莫拉菲','Molave','12'],
['200906','2009-07-18 13:00:00','21.7','117.4','970','35','25','西北西','260','80','','54412','','莫拉菲','Molave','12'],
['200906','2009-07-18 12:00:00','21.6','117.5','975','33','25','西北西','260','80','','54411','','莫拉菲','Molave','12'],
['200906','2009-07-18 11:00:00','21.6','117.7','975','33','25','西北西','260','80','','54410','','莫拉菲','Molave','12'],
['200906','2009-07-18 10:00:00','21.6','117.9','975','33','25','西北西','260','80','','54409','','莫拉菲','Molave','12'],
['200906','2009-07-18 09:00:00','21.5','118.2','975','33','25','西北西','260','80','','54408','','莫拉菲','Molave','12'],
['200906','2009-07-18 08:00:00','21.4','118.3','975','33','25','西北偏西','260','80','','54407','','莫拉菲','Molave','12'],
['200906','2009-07-18 07:00:00','21.4','118.5','975','33','25','西北西','260','80','','54406','','莫拉菲','Molave','12'],
['200906','2009-07-18 06:00:00','21.3','118.7','975','33','25','西北西','260','80','','54405','','莫拉菲','Molave','12'],
['200906','2009-07-18 05:00:00','21.2','119','975','33','','','260','60','','54404','','莫拉菲','Molave','12'],
['200906','2009-07-18 04:00:00','21.2','119.2','978','30','25','西北西','260','60','','54403','','莫拉菲','Molave','11'],
['200906','2009-07-18 03:00:00','21.1','119.4','978','30','25','西北偏西','260','60','','54402','','莫拉菲','Molave','11'],
['200906','2009-07-18 02:00:00','21','119.6','978','30','','','260','60','','54401','','莫拉菲','Molave','11'],
['200906','2009-07-18 01:00:00','21','120.1','978','30','25','西北偏西','260','60','','54400','','莫拉菲','Molave','11'],
['200906','2009-07-18 00:00:00','20.9','120.3','978','30','25','西北偏西','260','60','','54399','','莫拉菲','Molave','11'],
['200906','2009-07-17 23:00:00','20.8','120.5','978','30','20','西北偏西','260','60','','54398','','莫拉菲','Molave','11'],
['200906','2009-07-17 22:00:00','20.7','121','978','30','20','西北偏西','260','60','','54397','','莫拉菲','Molave','11'],
['200906','2009-07-17 21:00:00','20.7','121.2','978','30','20','西北偏西','260','60','','54396','','莫拉菲','Molave','11'],
['200906','2009-07-17 20:00:00','20.6','121.5','978','30','20','西北偏西','260','60','','54395','','莫拉菲','Molave','11'],
['200906','2009-07-17 19:00:00','20.4','121.8','980','28','20','西北西','260','60','','54394','','莫拉菲','Molave','10'],
['200906','2009-07-17 18:00:00','20.3','121.9','980','28','20','西北偏西','260','60','','54393','','莫拉菲','Molave','10'],
['200906','2009-07-17 17:00:00','20.2','122.1','980','28','20','西北偏西','200','50','','54392','','莫拉菲','Molave','10'],
['200906','2009-07-17 14:00:00','19.5','122.7','','25','','','200','50','','54391','','莫拉菲','Molave','10'],
['200906','2009-07-17 11:00:00','18.9','123.3','985','25','15','西北','200','50','','54390','','莫拉菲','Molave','10'],
['200906','2009-07-17 08:00:00','18.6','123.6','994','20','','','100','','','54389','','莫拉菲','Molave','8'],
['200906','2009-07-17 05:00:00','18.4','123.9','996','18','15','西北','100','','','54388','','莫拉菲','Molave','8'],
['200906','2009-07-17 02:00:00','17.9','124.1','996','18','15','西北','50','','','54387','','莫拉菲','Molave','8'],
['200906','2009-07-16 23:00:00','17.6','124.6','996','18','15','西北','','','','54386','','莫拉菲','Molave','8'],
['200906','2009-07-16 20:00:00','17.4','124.7','996','18','','','','','','54385','','莫拉菲','Molave','8']];

再下去字符串的拆分实在是太复杂了,不想写了
使用时只要参数为http://www.wztf121.com/Typhoon.aspx?id=
id后是台风的代码号,写一个循环就可以了
R夏至未至H
2009-07-31 · TA获得超过469个赞
知道小有建树答主
回答量:273
采纳率:100%
帮助的人:356万
展开全部

问题1:获取页面的源文件:innerHtml  能得到一个大字符串 包含所有信息

文体2:你需要的数据时从  var gAreaPointsData=[

[1,"泉州",118.582,24.9223,"AAAAAA",6,"777777",12], 这里开始

从  [180,"玉林",110.172319,22.620761,"AAAAAA",6,"777777",12]

];

 var iTyphoonCount=0;

 var iCurrentTyphoonCount=0;

结束

你用大字符串截取的方式substr的方式获取你需要的信息

然后解析这个字符串得到一个数组,就是你要的数据。

具体的解析方式楼上两位已经说得很清楚了。

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友f683cf5
2009-07-29 · TA获得超过369个赞
知道小有建树答主
回答量:522
采纳率:0%
帮助的人:373万
展开全部
查看源文件,很容易找到信息,不过貌似比较难获得地理位置
var arytm=[['200906','莫拉菲','Molave'],
['200905','苏迪罗','Soudelor'],
['200904','浪卡','Nangka'],
['200903','莲花','Linfa'],
['200902','灿鸿','Chan-hom'],
['200901','鲸鱼','Kujira'],
['200822','白海豚','Dolphin'],
['200821','红霞','Noul'],
['200820','海神','Haishen'],
['200819','美莎克','Maysak'],
['200818','巴威','Bavi'],
['200817','海高斯','Higos'],
['200816','米克拉','MEKKHALA'],
['200815','蔷薇','Jangmi'],
['200814','黑格比','Hagupit'],
['200813','森拉克','Sinlaku'],
['200812','鹦鹉','Nuri'],
['200811','黄蜂','Vongfong'],
['200810','巴蓬','Phanfone'],
['200809','北冕','Kammuri'],
['200808','凤凰','Fung-wong'],
['200807','海鸥','Kalmaegi'],
['200806','风神','Fengshen'],
['200805','娜基莉','Nakri'],
['200804','夏浪','Halong'],
['200803','麦德姆','Matmo'],
['200802','威马逊','Rammasun'],
['200801','浣熊','Neoguri'],
['200725','海贝思','Hagibis'],
['200724','米娜','Mitag'],
['200723','塔巴','Tapah'],
['200722','琵琶','Peipah'],
['200721','法茜','Faxai'],
['200720','剑鱼','Kajiki'],
['200719','玲玲','Lingling'],
['200718','杨柳','Podul'],
['200717','海燕','HAIYAN'],
['200716','罗莎','KROSA'],
['200715','利奇马','Lekima'],
['200714','范斯高','FRANCISCO'],
['200713','韦帕','Wipha'],
['200712','百合','Nari'],
['200711','丹娜丝','Danas'],
['200710','菲特','Fitow'],
['200709','圣帕','Sepat'],
['200708','蝴蝶','Wutip'],
['200707','帕布','Pabuk'],
['200706','未名','NAMELESS'],
['200705','天兔','Usagi'],
['200704','万宜','Man-yi'],
['200703','桃芝','Toraji'],
['200702','玉兔','Yutu'],
['200701','康妮','Kong-rey'],
['200624','潭美','Trami'],
['200623','尤特','Utor'],
['200622','榴莲','Durian'],
['200621','飞燕','Chebi'],
['200620','西马仑','Cimaron'],
['200619','苏力','Soulik'],
['200618','温比亚','Rumbia'],
['200617','贝碧嘉','Bebinca'],
['200616','象神','Xangsane'],
['200615','',''],
['200614','摩羯','Yagi'],
['200613','珊珊','Shanshan'],
['200612','伊欧凯','Ioke'],
['200611','清松','Sonamu'],
['200610','悟空','Wukong'],
['200609','宝霞','Bopha'],
['200608','桑美','Saomai'],
['200607','玛利亚','Maria'],
['200606','派比安','Prapiroon'],
['200605','格美','Kaemi'],
['200604','碧利斯','Bilis'],
['200603','艾云尼','Ewiniar'],
['200602','杰拉华','Jelawat'],
['200601','珍珠','Chanchu'],
['200523','布拉万','Bolaven'],
['200522','天秤','Tembin'],
['200521','启德','Kai-tak'],
['200520','鸿雁','Kirogi'],
['200519','龙王','Longwang'],
['200518','达维','Damrey'],
['200517','苏拉','Saola'],
['200516','韦森特','Vicente'],
['200515','卡努','Khanun'],
['200514','彩蝶','Nabi'],
['200513','泰利','Talim'],
['200512','古超','Guchol'],
['200511','玛娃','Mawar'],
['200510','珊瑚','Sanvu'],
['200509','麦莎','Matsa'],
['200508','天鹰','Washi'],
['200507','榕树','Banyan'],
['200506','尼格','Nalgae'],
['200505','海棠','Haitang'],
['200504','纳沙','Nesat'],
['200503','桑卡','Sonca'],
['200502','洛克','Roke'],
['200430','奥鹿','Noru'],
['200429','塔拉斯','Talas'],
['200428','南玛都','Nanmadol'],
['200426','梅花','MUIFA'],
['200425','洛坦','NOCK-TEN'],
['200424','蝎虎','Tokage'],
['200423','马鞍','Ma-on'],
['200422','米雷','MEARI'],
['200421','海马','HAIMA'],
['200420','莎莉嘉','SARIKA'],
['200419','桑达','SONGDA'],
['200418','艾利','AERE'],
['200417','暹芭','CHABA'],
['200416','鲇鱼','Megi'],
['200415','马勒卡','MALAKAS'],
['200414','云娜','RANANIM'],
['200413','莫兰蒂','meranti'],
['200412','玛瑙','malou'],
['200411','',''],
['200410','南川','namtheum'],
['200409','圆规','tiii'],
['200408','婷婷','tingting'],
['200407','蒲公英','mindule'],
['200406','电母','DIANMU'],
['200405','灿都','CHANTHU'],
['200404','康森','CONSON'],
['200403','奥麦斯','OMAIS'],
['200402','妮妲','NIDA'],
['200401','苏特','SUDAL'],
['200321','卢碧','LUPIT'],
['200320','尼伯特','NEPARTAK'],
['200319','茉莉','MELOR'],
['200318','芭玛','PARMA'],
['200317','凯莎娜','KETSANA'],
['200316','巨爵','KOPPU'],
['200315','彩云','CHOI_WAN'],
['200314','鸣蝉','MAEMI'],
['200313','杜鹃','DUJUAN'],
['200312','科罗旺','KROVANH'],
['200311','环高','Vamco'],
['200310','艾涛','Etau'],
['200309','莫拉克','MORAKOT'],
['200308','天鹅','KONI'],
['200307','伊布都','IMBUDO'],
['200306','苏迪罗','SOUDELOR'],
['200305','浪卡','NANGKA'],
['200304','莲花','LINFA'],
['200303','灿鸿','CHAN_HOM'],
['200302','鲸鱼','KUJIRA'],
['200301','欣欣','YANYAN'],
['200226','凤仙','PONGSONA'],
['200225','海神','HAISHEN'],
['200224','-','HUKO'],
['200223','美莎克','MAYSAK'],
['200222','巴威','BAVI'],
['200221','海高斯','HIGOS'],
['200220','米克拉','MEKKHALA'],
['200218','黑格比','HAGUPIT'],
['200216','森拉克','SINLAKU'],
['200215','鹿莎','RUSA'],
['200214','黄蜂','VONGFONG'],
['200213','巴蓬','PHANFONE'],
['200212','北冕','KAMMURI'],
['200211','凤凰','FUNG_WONG'],
['200210','海鸥','KALMAEGI'],
['200209','风神','FENGSHEN'],
['200208','娜基莉','NAKRI'],
['200207','夏浪','HALONG'],
['200206','查安特','CHATAAN'],
['200205','威马逊','RAMMASUN'],
['200204','浣熊','NOGURI'],
['200203','海贝思','HAGIBIS'],
['200202','米娜','MITAG'],
['200201','塔巴','TAPAH'],
['200124','剑鱼','KAJIKI'],
['200123','玲玲','LINGLING'],
['200122','杨柳','PODUL'],
['200121','海燕','HAIYAN'],
['200120','罗莎','KROSA'],
['200119','利奇马','LEKIMA'],
['200118','范斯高','FRANCISCO'],
['200117','韦帕','VIPA'],
['200116','百合','NARI'],
['200115','丹娜丝','DANAS'],
['200114','菲特','FITOW'],
['200113','圣帕','SEPAT'],
['200112','蝴蝶','WUTIP'],
['200111','帕布','PABUK'],
['200110','天兔','USAGI'],
['200109','万宜','MAN_YI'],
['200108','桃芝','TORAJI'],
['200107','玉兔','YUTU'],
['200106','康妮','KONG_REY'],
['200105','潭美','TRAMI'],
['200104','尤特','UTOR'],
['200103','榴莲','DURIAN'],
['200102','飞燕','CHEBI'],
['200101','西马仑','CIMARON'],
['200022','温比亚','Rumbia'],
['200021','贝碧嘉','Bebinca'],
['200020','象神','XANGSANE'],
['200019','魔羯','Yagi'],
['200018','珊珊','SHANSHAN'],
['200017','清松','SONAMU'],
['200016','悟空','WUKONG'],
['200015','宝霞','BOPHA'],
['200014','桑美','SAOMAI'],
['200013','玛莉亚','MARIA'],
['200012','派比安','PRAPIROON'],
['200011','格美','KAEMI'],
['200010','碧利斯','BILIS'],
['200009','艾云尼','EWINIAR'],
['200008','杰拉华','JELAWAT'],
['200007','珍珠','CHANCHU'],
['200006','布拉万','BOLAVEN'],
['200005','天秤','TEMBIN'],
['200004','启德','KAI_TAK'],
['200003','鸿雁','KIROGI'],
['200002','龙王','LONGWANG'],
['200001','达维','DAMREY']];
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
千锋教育
2015-12-20 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
展开全部
jsp传值给另一个jsp页面,主要的方式是将数据放在request对象中,然后在另一个页面拿到这个数据,执行SQL插入语句即可,代码如下:
A.jsp :通过post 和get、连接都可以传
a标签连接的:
<a herf='B.jsp?name=<%=name%>'>传递到B页面</a>
B.jsp :
B页面通过如下代码接收
<%
String name=request.getParameter("name");
String sql="insert into 表名 (列名) values(?)";
Connection conn=DBUtil.getConn();
try{
PreparedStatement pst=conn.preparedStatement(sql);
pst.setString(1,data);
pst.executeUpdate();
}catch(SQLException e){
e.printStackTrace();
}finally{
DBUtil.close(null,pst,conn);
}
%>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式