1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package com.wego.web.test;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Crawler {
public static void main(String[] args) {
try {
Elements artist = rawData.select("p[class=artist]");
Elements title = rawData.select("p[class=title]");
List<String> artist2 = new ArrayList<>();
List<String> title2 = new ArrayList<>();
for(Element e : artist) {
artist2.add(e.text());
}
for(Element e : title) {
title2.add(e.text());
}
System.out.println(artist2);
System.out.println("---------------");
System.out.println(title2);
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
|
cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.wego.web.test; import java.util.ArrayList; import java.util.List; import org.jsoup.Connection; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class Crawler2 { public static void main(String[] args) { try { Document rawData = Jsoup.connect("https://music.bugs.co.kr/recomreview?&order=listorder&page=2").timeout(10*1000).get(); Elements artist = rawData.select("aside[class=recommendReview] p"); List<String> artist2 = new ArrayList<>(); for(Element e : artist) { artist2.add(e.text()); } System.out.println(artist2); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } } | cs |
'Java' 카테고리의 다른 글
[자바 객체지향] is-a 관계와 has-a 관계의 비교 (0) | 2020.05.01 |
---|---|
[자바 객체지향] 얕은 복사와 깊은 복사 비교하기 (feat. 스미스와 전우치) (0) | 2020.05.01 |
[자바 8] 람다 스트림 예문 PersonService.java (출처: 자바의정석) (0) | 2020.04.30 |
[자바 알고리즘] 팩토리얼 Factorial.java (0) | 2020.04.30 |
[자바 8] 람다 Lambda 5 가지 종류 (0) | 2020.04.30 |