- import java.util.HashMap;
- import java.util.Map;
- import org.htmlparser.Node;
- import org.htmlparser.NodeFilter;
- import org.htmlparser.Parser;
- import org.htmlparser.tags.LinkTag;
- import org.htmlparser.util.NodeList;
- import com.yao.http.HttpRequester;
- import com.yao.http.HttpRespons;
-
-
-
-
-
-
- public class Test {
- public static void main(String[] args) {
- try {
-
-
- Map<String, String> map = new HashMap<String, String>();
- HttpRequester request = new HttpRequester();
- HttpRespons hr = request.sendGet("http://www.baidu.com");
-
- Parser parser = Parser.createParser(hr.getContent(), hr
- .getContentEncoding());
- try {
-
- NodeList nodeList = parser
- .extractAllNodesThatMatch(new NodeFilter() {
-
- public boolean accept(Node node) {
- if (node instanceof LinkTag)
- return true;
- return false;
- }
- });
-
- for (int i = 0; i < nodeList.size(); i++) {
- LinkTag n = (LinkTag) nodeList.elementAt(i);
- System.out.print(n.getStringText() + " ==>> ");
- System.out.println(n.extractLink());
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
posted @
2011-03-23 00:09
Hongten
阅读(
11616)
评论()
编辑
收藏
举报