取得 html 页面中的数据??

来源:百度知道 编辑:UC知道 时间:2024/06/20 09:23:54
在一个html网页中,有一个table,例如

姓名 分数
张三 100

我如何取得姓名和分数,我是从其他网站的页面取得,所以只能在html的源文件中取得?具体怎么实现,要用Java语言。。。

URL url = new URL("http://www.baidu.com");
InputStream stream = url.openStream();

这样可以获得路径的全部信息,下面怎么做就要自己去分解了。

需要什么自己提取。

给你个例子:
public static void main(String[] args) {
try {
URL url = new URL("http://www.baidu.com");
InputStream stream = url.openStream();
OutputStream bos = new FileOutputStream("c:/text.html");
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}

你想要的是数据抓取吧,这还真不是一般人就能干的,首先要找好资源,然后就是分析数据来源(html)的规律,找到规律然后进行抓取,一般都是用String类的indexOf定位, split分割获得数组, 等方法... 具体问题需要具体分析.

你这是天马行空的想法