首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Jsoup介绍及解析常用方法

jsoup 是一款 Java 的HTML 解析器,可直接解析某个URL地址、HTML文本内容。它提供了一套非常省力的API,可通过DOM,CSS以及类似于JQuery的操作方法来取出和操作数据 jsoup的主要功能如下: 从一个URL,文件或字符串中解析HTML; 使用DOM或CSS选择器来查找、取出数据; 可操作HTML元素、属性、文本; jsoup解析 Jsoup提供一系列的静态解析方法生成Document对象 static Document parse(File in, String charsetName) static Document parse(File in, String charsetName, String baseUri) static Document parse(InputStream in, String charsetName, String baseUri) static Document parse(String html) static Document parse(String html, String baseUri) static Document parse(URL url, int timeoutMillis) static Document parseBodyFragment(String bodyHtml) static Document parseBodyFragment(String bodyHtml, String baseUri) 其中baseUri表示检索到的相对URL是相对于baseUriURL的 其中charsetName表示字符集 Connection connect(String url) 根据给定的url(必须是http或https)来创建连接 Connection 提供一些方法来抓去网页内容 Connection cookie(String name, String value) 发送请求时放置cookie Connection data(Map<String,String> data) 传递请求参数 Connection data(String... keyvals) 传递请求参数 Document get() 以get方式发送请求并对返回结果进行解析 Document post()以post方式发送请求并对返回结果进行解析 Connection userAgent(String userAgent) Connection header(String name, String value) 添加请求头 Connection referrer(String referrer) 设置请求来源 jsoup提供类似JS获取html元素: getElementById(String id) 用id获得元素 getElementsByTag(String tag) 用标签获得元素 getElementsByClass(String className) 用class获得元素 getElementsByAttribute(String key) 用属性获得元素 同时还提供下面的方法提供获取兄弟节点:siblingElements(), firstElementSibling(), lastElementSibling();nextElementSibling(), previousElementSibling() 获得与设置元素的数据 attr(String key) 获得元素的数据 attr(String key, String value) 设置元素数据 attributes() 获得所以属性 id(), className() classNames() 获得id class得值 text()获得文本值 text(String value) 设置文本值 html() 获取html html(String value)设置html outerHtml() 获得内部html data()获得数据内容 tag() 获得tag 和 tagName() 获得tagname 操作html元素: append(String html), prepend(String html) appendText(String text), prependText(String text) appendElement(String tagName), prependElement(String tagName) html(String value) jsoup还提供了类似于JQuery方式的选择器 采用选择器来检索

02

jQuery学习笔记之概念(1)

jQuery学习笔记之概念(1) ——————————————————————学习目录———————————————————— 1.概念 2.特点 3.选择器 4.DOM操作 5.事件 6.jQuery的Ajax ———————————————————————————————————————————————— 前言:当前流行的JavaScript库有: jQuery、MooTools、Prototype、Dojo、YUI、EXT_JS、DWR 1.概念: 核心库、UI和插件等。 jQuery是继承prototype之后又一个优秀的JavaScript库。现在jQuery主要包括核心库、UI和插件等。。 jQuery凭借着简介的语法和跨平台的兼容性,极大地简化了JavaScript开发人员遍历HTML文档、操作DOM。处理事件执行动画和开发ajax的操作。

02
领券