【发布时间】:2011-04-18 18:34:17
【问题描述】:
我知道我的问题有很多主题,但我找不到对我的答案有用的解决方案。我可以连接到网站并用 Java 逐行阅读,现在这是我的问题。我想从 html 页面解析特定信息。此页面包括 5 天的天气预报。例如预测标签的日期是这样的;
//date of forecast
< th id="ctl00_mpBody_thmGun1" class="arkaTrh">19 April< /th >
//Min weather:
< td id="ctl00_mpBody_thmMin1" class="minS">8< /td>
//Max weather
< td id="ctl00_mpBody_thmMax1" class="maxS">17< /td>
second day and others tags continue like this,
< th id="ctl00_mpBody_thmGun2" class="arkaTrh">20 April< /th >
.
.
.
根据这些标签,我需要解析4月19日、17日和8日。
【问题讨论】:
-
我忘记写了,我需要使用正则表达式:)
-
download.oracle.com/javase/tutorial/essential/regex/index.html /class=\"arkaTrh\">([0-9a-zA-Z ]+)/
-
在使用正则表达式解析 HTML 之前要仔细考虑。见codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
标签: java html regex parsing web-scraping