잦은 OS 업데이트로 매일매일 홈페이지에 들어가서 확인 하기가 번거로워서 웹 크롤링을 통해 이메일로 해당 업데이트 내용을 전달해주는 프로그램을 만들었다.

웹 크롤링 툴에는 크게 두가지가 있는데, Jsoup과 selenium 이고 둘의 간단한 사용법 이나 차이는 아래의 글에 정리 해 놓았다.
웹 크롤링 비교: Jsoup vs Selenium, 속도·성능·활용 차이 정리
웹 크롤링을 할 때 가장 많이 쓰이는 것들이 있다. 웹 스크래핑 라이브러리 Jsoup과 브라우저 자동화 프레임워크 Selenium이다. 오늘은 이 두개를 비교해서 어떨 때 사용 해야 하는지 정리했다. Jsoup
henniee.tistory.com
웹 크롤링을 시작하기 전에는 어떤 정보를 어디서 가져올지 정리해야 한다. 나는 iOS 업데이트 정보만 확인하면 되었기 때문에 Apple Developer 사이트 구조를 간단히 파악해 준다.

페이지를 살펴보면,
1) section 태그 안에 각각의 업데이트 정보가 들어 있고
2) 그 안의 h2 태그에서 버전명(iOS 18.x 등) 을 가져온다.
3) 바로 아래의 p 태그에서는 배포 날짜를 가져온다.
4) 맨 마지막에는 릴리즈 노트 링크가 있다.
즉, 크롤링 로직은 버전 → 날짜 → 릴리즈 노트 순서대로 추출하면 된다.
//사이트 연결하기
Document doc = Jsoup.connect(APPLE_RELEASES_URL).get();
// 클래스가 .article-content-container 인 selection 요소들을 뽑아준다.
Elements sections = doc.select("section.article-content-container");
List<IosVersionInfo> latestVersions = new ArrayList<>(); //값을 담을 리스트 만들기
LocalDate latestDate = null; // 날짜
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH); //날짜 포메팅
for (Element section : sections) { //selection 뽑아 놓은 요소들을 돌면서 원하는 값들을 매칭 시켜준다
Element h2 = section.selectFirst("h2:containsOwn(iOS)"); //iOS 를 가진 버전 이름
if (h2 != null) {
String version = h2.text();
//날짜세팅
Element dateElement = section.selectFirst("p.article-date");
if (dateElement == null)
continue;
String dateText = dateElement.text();
LocalDate currentDate;
try {
currentDate = LocalDate.parse(dateText, formatter);
} catch (DateTimeParseException e) {
continue;
}
// 릴리즈 노트 <a> 태그 추출
Element releaseNoteLink = section.selectFirst("a.more:containsOwn(View release notes)");
String releaseNoteUrl = releaseNoteLink != null
? "https://developer.apple.com" + releaseNoteLink.attr("href")
: null;
}
}
'spring 스프링' 카테고리의 다른 글
| Spring Boot Gradle 프로젝트에서 SMTP 이메일 전송하기 (0) | 2025.08.28 |
|---|---|
| 안드로이드 업데이트 자동 확인: 웹 크롤링으로 이메일 알림 만들기 (0) | 2025.08.26 |
| Spring CORS 설정: WebConfig 작성부터 wildcard '*', withCredentials 문제 해결까지 (1) | 2025.06.26 |
| Spring Data JPA 페이징 구현하기 (SpringBoot 적용) (0) | 2025.06.02 |
| The method builder() is undefined for the type 오류 (해결2) (0) | 2025.04.05 |