请帮忙.如何从USGS网站获取地震信息? [英] Help,please. how to get the earthquake information from USGS web site?

查看:737
本文介绍了请帮忙.如何从USGS网站获取地震信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:
我想获得USGS网站的地震信息.
该URL为: /a> [ ^ ]

我只想要感兴趣的参数,

Hi:
I want to get the earthquake information for USGS web site.
the URL is:http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/quakes_big.php[^]

I only want to the interested parameter,

MAG     UTC DATE-TIME      LAT      LON      DEPTH    Region

MAP  6.2    2011/09/03 04:49:01      -56.551      -27.039   106.0    SOUTH SANDWICH ISLANDS REGION
MAP  5.1    2011/09/03 01:25:39       52.056     -171.567   51.2     FOX ISLANDS, ALEUTIAN ISLANDS, ALASKA
MAP  5.8    2011/09/03 01:06:56      -12.784      166.672   101.2    SANTA CRUZ ISLANDS



我想使用Java来获取Web表格的内容.
正则表达式可能是最好的方法.
有人可以帮我做正则表达式吗?

非常感谢!



I want to use java to get the contents of the web''s table.
the regular-expression may be the best way.
Could anyone help me on regular-expression?

Thanks a lot!

推荐答案

Pattern p = Pattern.compile("<table([\\s\\S]+?)>([\\s\\S]+?)</table>",Pattern.MULTILINE);// find the tables contents.
    Matcher m = p.matcher(sb.toString());
    while(m.find()){
//    System.out.println(m.group()); //fine the tables content is OK
    Pattern p1 = Pattern.compile("<table.*>(<tr>(<td.*>.*</td>){6}</tr>)+</table>");//may be something wrong in the line
    Matcher m1 = p1.matcher(m.group());
    if (m1.find()) {
       System.out.println(m1.group(0)+"__"+m1.group(4));
    }
    System.out.println("-----------------------");
    }




请帮忙.




please help.


以下方法效果很好,但这不是最好的方法.可以进一步优化吗?
the following do well,but it is not the best. Could it be Optimized more?
Pattern p = Pattern.compile("<table([\\s\\S]+?)>([\\s\\S]+?)</table>",Pattern.MULTILINE|Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(sb.toString());
String str="";
 while(m.find()){
     Pattern pTr = Pattern.compile("<tr.*?>.*?<\\s*/tr.*?>");
    Matcher mTr = pTr.matcher(m.group());
     Pattern pTd = Pattern.compile("<td.*?>.*?<\\s*/td.*?>");
     Matcher mTd = null;
    while (mTr.find()) {
         mTd = pTd.matcher(mTr.group());
        while (mTd.find()) {
            str=str+(mTd.group().replaceAll("<.*?>", "").replace("&nbsp;", "") + "\t");
           }
        System.out.println(str );
        str="";
      }
   }


这篇关于请帮忙.如何从USGS网站获取地震信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆