博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jsoup测试例子
阅读量:4309 次
发布时间:2019-06-06

本文共 4107 字,大约阅读时间需要 13 分钟。

1、测试代码

 

import java.io.File; import java.io.IOException;   import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements;   public class Test {     public static void main(String[] args) {         Test t = new Test();         t.parseUrl();     }       public void parseUrl() {         try {             Document doc = Jsoup.connect("http://www.baidu.com/").get();             Elements hrefs = doc.select("a[href]");             System.out.println(hrefs);             System.out.println("------------------");             System.out.println(hrefs.select("[href^=http]"));         } catch (IOException e) {             e.printStackTrace();         }     } }

 

2、编译及执行

  1. javac -cp jsoup-1.7.1.jar:. Test.java
  2. java -cp jsoup-1.7.1.jar:. Test



3、测试结果

    1. <a href="http://www.baidu.com/gaoji/preferences.html" name="tj_setting">搜索设置</a>
    2. <a href="https://passport.baidu.com/v2/?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2F" name="tj_login" id="lb" οnclick="return false;">登录</a>
    3. <a href="https://passport.baidu.com/v2/?reg&amp;regType=1&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2F" target="_blank" name="tj_reg" class="reg">注册</a>
    4. <a href="http://news.baidu.com">新&nbsp;闻</a>
    5. <a href="http://tieba.baidu.com">贴&nbsp;吧</a>
    6. <a href="http://zhidao.baidu.com">知&nbsp;道</a>
    7. <a href="http://music.baidu.com">音&nbsp;乐</a>
    8. <a href="http://image.baidu.com">图&nbsp;片</a>
    9. <a href="http://video.baidu.com">视&nbsp;频</a>
    10. <a href="http://map.baidu.com">地&nbsp;图</a>
    11. <a href="#" name="ime_hw">手写</a>
    12. <a href="#" name="ime_py">拼音</a>
    13. <a href="#" name="ime_cl">关闭</a>
    14. <a href="http://baike.baidu.com">百科</a>
    15. <a href="http://wenku.baidu.com">文库</a>
    16. <a href="http://www.hao123.com">hao123</a>
    17. <a href="http://www.baidu.com/more/">更多&gt;&gt;</a>
    18. <a id="seth" οnclick="h(this)" href="/" οnmοusedοwn="return ns_c({'fm':'behs','tab':'homepage','pos':0})">把百度设为主页</a>
    19. <a id="setf" href="http://www.baidu.com/cache/sethelp/index.html" οnmοusedοwn="return ns_c({'fm':'behs','tab':'favorites','pos':0})" target="_blank">把百度设为主页</a>
    20. <a href="http://www.baidu.com/search/baidukuaijie_mp.html" target="_blank" οnmοusedοwn="return ns_c({'fm':'behs','tab':'kuaijie','pos':1})">把百度添加到桌面</a>
    21. <a href="http://e.baidu.com/?refer=888" οnmοusedοwn="return ns_c({'fm':'behs','tab':'btlink','pos':2})">加入百度推广</a>
    22. <a href="http://top.baidu.com">搜索风云榜</a>
    23. <a href="http://home.baidu.com">关于百度</a>
    24. <a href="http://ir.baidu.com">About Baidu</a>
    25. <a href="/duty/">使用百度前必读</a>
    26. <a href="http://www.miibeian.gov.cn" target="_blank">京ICP证030173号</a>
    27. ------------------
    28. <a href="http://www.baidu.com/gaoji/preferences.html" name="tj_setting">搜索设置</a>
    29. <a href="https://passport.baidu.com/v2/?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2F" name="tj_login" id="lb" οnclick="return false;">登录</a>
    30. <a href="https://passport.baidu.com/v2/?reg&amp;regType=1&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2F" target="_blank" name="tj_reg" class="reg">注册</a>
    31. <a href="http://news.baidu.com">新&nbsp;闻</a>
    32. <a href="http://tieba.baidu.com">贴&nbsp;吧</a>
    33. <a href="http://zhidao.baidu.com">知&nbsp;道</a>
    34. <a href="http://music.baidu.com">音&nbsp;乐</a>
    35. <a href="http://image.baidu.com">图&nbsp;片</a>
    36. <a href="http://video.baidu.com">视&nbsp;频</a>
    37. <a href="http://map.baidu.com">地&nbsp;图</a>
    38. <a href="http://baike.baidu.com">百科</a>
    39. <a href="http://wenku.baidu.com">文库</a>
    40. <a href="http://www.hao123.com">hao123</a>
    41. <a href="http://www.baidu.com/more/">更多&gt;&gt;</a>
    42. <a id="setf" href="http://www.baidu.com/cache/sethelp/index.html" οnmοusedοwn="return ns_c({'fm':'behs','tab':'favorites','pos':0})" target="_blank">把百度设为主页</a>
    43. <a href="http://www.baidu.com/search/baidukuaijie_mp.html" target="_blank" οnmοusedοwn="return ns_c({'fm':'behs','tab':'kuaijie','pos':1})">把百度添加到桌面</a>
    44. <a href="http://e.baidu.com/?refer=888" οnmοusedοwn="return ns_c({'fm':'behs','tab':'btlink','pos':2})">加入百度推广</a>
    45. <a href="http://top.baidu.com">搜索风云榜</a>
    46. <a href="http://home.baidu.com">关于百度</a>
    47. <a href="http://ir.baidu.com">About Baidu</a>
    48. <a href="http://www.miibeian.gov.cn" target="_blank">京ICP证030173号</a>

 

转载于:https://www.cnblogs.com/licomeback/articles/3091167.html

你可能感兴趣的文章
五大串口的基本原理
查看>>
PCB设计技巧与注意事项
查看>>
linux进程之间通讯常用信号
查看>>
main函数带参数
查看>>
PCB布线技巧
查看>>
关于PCB设计中过孔能否打在焊盘上的两种观点
查看>>
PCB反推理念
查看>>
京东技术架构(一)构建亿级前端读服务
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>
Linux 系统挂载数据盘
查看>>
Git基础(三)--常见错误及解决方案
查看>>
Git(四) - 分支管理
查看>>
PHP Curl发送数据
查看>>
HTTP协议
查看>>
HTTPS
查看>>