Java爬取网页指定内容

  • 爬取网页文字:
  • import org.jsoup.Jsoup;
    import org.junit.Test;

    import java.io.IOException;

    public class Crawling {


    public static void Test() throws IOException {
    Jsoup.connect("https://soccer.hupu.com/").get().body().
    getElementsByClass("list-item"). //class="list-item-title"
    forEach(e->{
    System.out.println(e.text());
    });

    }

    public static void main(String[] args) {
    try {
    Test();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    }
  • 爬取网页图片地址:
  • import org.jsoup.Jsoup;
    import org.junit.Test;

    import java.io.IOException;

    public class Crawling {

    public static void Test() throws IOException {
    Jsoup.connect("https://soccer.hupu.com/").get().body().
    getElementsByClass("list-item-img").
    forEach(e->{
    System.out.println(e.attr("src")); //src标签图片地址
    });
    }

    public static void main(String[] args) {
    try {
    Test();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    }
上一篇:彻底解决分布式环境下Redisson消息队列监听重复执行问题


下一篇:业余无线电之配置Orbitron My DDE 自动推送多普勒频率至SDRSharp程序中