爬虫 //获取元素中的数据

 //    <!--jsoup解析工具所需依赖-->
//        <dependency>
//            <groupId>org.jsoup</groupId>
//            <artifactId>jsoup</artifactId>
//            <version>1.10.3</version>
//        </dependency>
//
//        <dependency>
//            <groupId>junit</groupId>
//            <artifactId>junit</artifactId>
//            <version>4.12</version>
//            <scope>test</scope>
//        </dependency>
//
//        <dependency>
//            <groupId>commons-io</groupId>
//            <artifactId>commons-io</artifactId>
//            <version>2.6</version>
//        </dependency>
//
//        <dependency>
//            <groupId>org.apache.commons</groupId>
//            <artifactId>commons-lang3</artifactId>
//            <version>3.7</version>
//        </dependency>

package day05;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.File;
import java.io.IOException;

public class CESHIDE {
    public static void main(String[] args) throws IOException {
        
     //获取元素中的数据
    //解析文件,获取Document
        Document parse = Jsoup.parse(new File("C:\\Users\\LX\\Desktop\\新建文本文档.txt"), "utf-8");
    //根据id获取元素doc.getElementById("test");
     //根据id获取元素
        Element test = parse.getElementById("mobileclient");
       //打印
//        System.out.println(test.id());

     //  从元素中获取className/12.str = element.className();

     //   获取元素class内容
//        String s = test.className();
//        System.out.println(s);

        //获取多个class提示内容 如果有多个的话
//        Set<String> strings = test.classNames();
//        for (String string : strings) {
//            System.out.println(string);
//        }

//        从元素中获取属性的值attr
        /*String id = test.attr("id");
        System.out.println(id);
        String id = test.attr("class");
        System.out.println(id);*/

//    从元素中获取所有属性
       /* Attributes attributes = test.attributes();
        System.out.println(attributes.toString());*/

//        从元素中获取文本内容 text
        String text = test.text();
        System.out.println(text);

    }
}

相关推荐

  1. 爬虫 //获取元素数据

    2024-04-20 15:42:06       38 阅读
  2. js获取dom元素宽度数值

    2024-04-20 15:42:06       61 阅读
  3. vue项目获取 iframe DOM元素

    2024-04-20 15:42:06       59 阅读
  4. 爬虫获取人人车网站车辆信息

    2024-04-20 15:42:06       37 阅读
  5. Python爬虫获取古诗文网古诗文

    2024-04-20 15:42:06       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-20 15:42:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-20 15:42:06       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-20 15:42:06       82 阅读
  4. Python语言-面向对象

    2024-04-20 15:42:06       91 阅读

热门阅读

  1. 保存的链接

    2024-04-20 15:42:06       29 阅读
  2. 偏微分方程笔记

    2024-04-20 15:42:06       34 阅读
  3. 基于Nacos+SpringCloudAlibaba的服务治理

    2024-04-20 15:42:06       33 阅读
  4. 手机移动端网卡信息获取原理分析

    2024-04-20 15:42:06       34 阅读
  5. 010 springboot整合mybatis-plus 登录页面和首页不拦截

    2024-04-20 15:42:06       31 阅读
  6. 2024.4.18 Python爬虫复习day06 可视化2

    2024-04-20 15:42:06       29 阅读
  7. 机器学习总结

    2024-04-20 15:42:06       36 阅读
  8. 深入理解python中的subprocess模块

    2024-04-20 15:42:06       27 阅读
  9. 开发语言漫谈-PHP

    2024-04-20 15:42:06       33 阅读
  10. Django中如何实现防御CSRF攻击呢

    2024-04-20 15:42:06       39 阅读
  11. 开发语言漫谈-go

    2024-04-20 15:42:06       33 阅读