크롤링 대상


전략
1] ul.section_list_ranking > li > a 의 구조
2] a tag에 title 속성에서 값을 get 하자
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
class Cwl {
String target_url;
Cwl() {
this.target_url = "https://news.naver.com/main/main.nhn?mode=LSD&mid=shm&sid1=101";
}
public void requestUrl() throws IOException {
Document doc = Jsoup.connect(this.target_url).get();
Element element = doc.selectFirst("ul.section_list_ranking");
Elements elements = element.select("li > a");
for (Element e : elements) {
System.out.println(e.attr("title"));
}
}
}
public class stu01 extends Cwl{
public static void main(String[] args) throws IOException {
Cwl cwl_object = new Cwl();
cwl_object.requestUrl();
} // end of main function
}
결과

'언어 > java' 카테고리의 다른 글
java + elasticsearch highlevel rest api (0) | 2020.07.04 |
---|---|
정올 1523 (9) (0) | 2020.05.06 |
정올 1338번문제 (8일차) (2) | 2020.05.03 |
1314 정올 (7-2) (0) | 2020.05.02 |
1307 정올 7일차 (0) | 2020.05.02 |