爬虫 Selector 选择器查找元素

//    <!--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 java.io.File;
import java.io.IOException;

public class jixucheshi {
    public static void main(String[] args) throws IOException {
        
//        Selector 选择器查找元素
        Document parse = Jsoup.parse(new File("C:\\Users\\LX\\Desktop\\新建文本文档.txt"), "utf-8");
       //  通过标签查找元素,比如:span  a div
        /*Elements select = parse.select("li");
        for (Element element : select) {
            System.out.println(element.text());
        }*/
//#id:通过ID查找元素,比如:#city_bi 需要加#号
//Element element = doc.select("#city bi").first();
        /*Element first = parse.select("#mobileclient").first();
        System.out.println(first.text());*/

//.class:通过class名称查找元素,比如:.class_a
        /*Element first = parse.select(".dropdown").first();
        System.out.println(first.text());*/

//[attribute]:利用属性查找元素,比如:[abc] 需要加[]   除了class id 以外的都叫元素
       /* Element first = parse.select("[target]").first();
        System.out.println(first.text());*/

//[attr=value]:利用属性值来查找元素,比如:[class=s name] 完整的名字
        /*Element first = parse.select("[data-sudaclick=nav_app_sports_p]").first();
        System.out.println(first.text());*/
    }
}

相关推荐

  1. 爬虫 Selector 选择查找元素

    2024-04-24 07:28:02       15 阅读
  2. 选择和伪元素选择

    2024-04-24 07:28:02       15 阅读
  3. css伪类和伪元素选择

    2024-04-24 07:28:02       7 阅读
  4. Selenium WebDriver提供By.CSS_SELECTOR定位元素方法

    2024-04-24 07:28:02       17 阅读
  5. css使用伪类选择选择特定模式的元素

    2024-04-24 07:28:02       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-24 07:28:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-24 07:28:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-24 07:28:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-24 07:28:02       20 阅读

热门阅读

  1. 系统架构设计

    2024-04-24 07:28:02       14 阅读
  2. 第三章、汇编2

    2024-04-24 07:28:02       11 阅读
  3. Android|记一个导致 logback 无法输出日志的问题

    2024-04-24 07:28:02       15 阅读
  4. Visual Studio C++ 示例

    2024-04-24 07:28:02       12 阅读
  5. C# 设置窗体最大化,以及窗体最大化时的坐标

    2024-04-24 07:28:02       14 阅读
  6. 练习题(2024/4/23)

    2024-04-24 07:28:02       13 阅读
  7. GIT 仓库迁移

    2024-04-24 07:28:02       12 阅读
  8. 数据结构 - 顺序表实现通讯录

    2024-04-24 07:28:02       14 阅读
  9. Cocos Creator 3D资源的导入与动画播放详解

    2024-04-24 07:28:02       12 阅读