最后一个例子: testChkl.java
import java.net.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.xpath.*;
public class testChkl {
public static void main(String[] args) {
try {
URL url = new URL("http://www.delphibbs.com/delphibbs/chkl.asp?recnum=0");
do
cumentBuilderFactory dfactory =do
cumentBuilderFactory.newInstance();
do
cumentdo
c = dfactory.newDocumentBuilder().parse(url.openStream());
String xpath = "/DFWML/HEADER/RecCount";
Node n = XPathAPI.selectSingleNode(doc, xpath);
if (n != null) {
System.out.println("Today, up to now, the number of the updated letters on delphibbs.com is: " +
n.getFirstChild().getNodeValue());
}
}
catch(Exception e) {
System.err.println(e.toString());
}
}
}
编译: C:/>javac -classpath c:/jaxp-1.1/xalan.jar testChkl.java
运行: C:/>java -classpath .;c:/jaxp-1.1/xalan.jar testChkl
Today, up to now, the number of the updated letters on delphibbs.com is: 180
功能说明:
从大富翁论坛获得 DFWML,分析得到今天目前为止,大富翁论坛中更新贴子的数量.
相当于我在问题"新版大富翁论坛揭密之一:数据提取"(lid=495235)中发布的 Delphi + MSXML 小程序一样的功能.
上面所有的例子再加上些描述可以出篇文章了
//如果使用代理服务器处理
System.getProperties().put("proxySet", "true" );
System.getProperties().put("proxyHost","10.10.10.18");
System.getProperties().put("proxyPort","80");
//如果使用代理服务器需要密码验证
sun.misc.BASE64Encoder B64Encoder = new sun.misc.BASE64Encoder();
String tempString = "yysun:xxxxxx";
String auth = "Basic " + new sun.misc.BASE64Encoder().encode (tempString.getBytes());
URLConnection connection = url.openConnection();
connection.setRequestProperty("Proxy-Authorization", auth);
Documentdo
c = dfactory.newDocumentBuilder().parse(connection.getInputStream());