diff --git a/src/main/generated/zerobase/sijak/persist/domain/QLecture.java b/src/main/generated/zerobase/sijak/persist/domain/QLecture.java index c01cad6..f826770 100644 --- a/src/main/generated/zerobase/sijak/persist/domain/QLecture.java +++ b/src/main/generated/zerobase/sijak/persist/domain/QLecture.java @@ -72,6 +72,8 @@ public class QLecture extends EntityPathBase { public final ListPath teachers = this.createList("teachers", Teacher.class, QTeacher.class, PathInits.DIRECT2); + public final StringPath tel = createString("tel"); + public final StringPath textBookName = createString("textBookName"); public final StringPath textBookPrice = createString("textBookPrice"); diff --git a/src/main/java/zerobase/sijak/persist/domain/Lecture.java b/src/main/java/zerobase/sijak/persist/domain/Lecture.java index 5eb4c5e..f7bd89c 100644 --- a/src/main/java/zerobase/sijak/persist/domain/Lecture.java +++ b/src/main/java/zerobase/sijak/persist/domain/Lecture.java @@ -8,11 +8,9 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import zerobase.sijak.dto.crawling.LectureCreateRequest; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; @Entity @@ -32,6 +30,8 @@ public class Lecture { @Size(max = 1000) private String description; + private String tel; + private String price; @OneToMany(mappedBy = "lecture") diff --git a/src/main/java/zerobase/sijak/service/scrap/GangseoScrapService.java b/src/main/java/zerobase/sijak/service/scrap/GangseoScrapService.java index fae27ca..604c310 100644 --- a/src/main/java/zerobase/sijak/service/scrap/GangseoScrapService.java +++ b/src/main/java/zerobase/sijak/service/scrap/GangseoScrapService.java @@ -10,7 +10,6 @@ import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.WebDriverWait; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import zerobase.sijak.exception.Code; @@ -41,7 +40,7 @@ public class GangseoScrapService { //@Scheduled(fixedRate = 10000000) public void scrapNowon() throws CustomException { try { - String name = "", time = "", price = "", href = "", startDate = "", endDate = ""; + String name = "", time = "", price = "", href = "", startDate = "", endDate = "", tel = ""; int capacity = 1, lId = -1, tId = -1, cId = -1; LocalDateTime deadline = LocalDateTime.now(); log.info("deadline : {}", deadline); @@ -93,6 +92,10 @@ public void scrapNowon() throws CustomException { if (!cols.get(cols.size() - 1).getText().trim().equals("수강신청")) continue; log.info("수강신청 여부 통과"); + WebElement telInfo = driver.findElement(By.xpath("/html/body/footer/div[2]/div[2]/address/a[1]")); + tel = telInfo.getText(); + log.info("tel = {}", tel); + System.out.println("2222"); for (int j = 3; j < cols.size(); j++) { String content = cols.get(j).getText(); @@ -148,6 +151,7 @@ public void scrapNowon() throws CustomException { .certification("") .dayOfWeek("") .target("") + .tel(tel) .textBookName("") .textBookPrice("") .thumbnail("") diff --git a/src/main/java/zerobase/sijak/service/scrap/MapoScrapService.java b/src/main/java/zerobase/sijak/service/scrap/MapoScrapService.java index 252ee1c..63723fd 100644 --- a/src/main/java/zerobase/sijak/service/scrap/MapoScrapService.java +++ b/src/main/java/zerobase/sijak/service/scrap/MapoScrapService.java @@ -10,7 +10,6 @@ import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.WebDriverWait; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import zerobase.sijak.exception.Code; @@ -46,7 +45,7 @@ public class MapoScrapService { //@Scheduled(fixedRate = 10000000) public void scrapMapo() throws CustomException { try { - String name = "", time = "", price = "", href = "", teacherName = "", startDate = "", endDate = ""; + String name = "", time = "", price = "", href = "", teacherName = "", startDate = "", endDate = "", tel = ""; int capacity = 1, lId = -1, tId = -1, cId = -1; LocalDateTime deadline = LocalDateTime.now(); @@ -75,6 +74,10 @@ public void scrapMapo() throws CustomException { WebElement specificTable = driver.findElement(By.xpath("//*[@id=\"bo_list\"]/div/div[1]/table")); WebElement specificTbody = specificTable.findElement(By.tagName("tbody")); List rows = specificTbody.findElements(By.tagName("tr")); + + WebElement telInfo = driver.findElement(By.xpath("//*[@id=\"ft\"]/div[2]/ul/li[1]/p[4]/span")); + tel = telInfo.getText().split(":")[1].replace(" ", ""); + log.info("tel: {}", tel); // 읽을 row 가 없다면 -> 크롤링 종료 if (rows.size() == 1) { System.out.println("specificTbody is empty"); @@ -151,6 +154,7 @@ public void scrapMapo() throws CustomException { .division("정기 클래스") .latitude(37.556445) .need("") + .tel(tel) .textBookName("") .textBookPrice("") .thumbnail("") diff --git a/src/main/java/zerobase/sijak/service/scrap/NowonScrapService.java b/src/main/java/zerobase/sijak/service/scrap/NowonScrapService.java index 6c0799e..df41613 100644 --- a/src/main/java/zerobase/sijak/service/scrap/NowonScrapService.java +++ b/src/main/java/zerobase/sijak/service/scrap/NowonScrapService.java @@ -37,7 +37,7 @@ public class NowonScrapService { //@Scheduled(fixedRate = 10000000) public void scrapNowon() throws CustomException { try { - String name = "", time = "", price = "", href = "", startDate = "", endDate = ""; + String name = "", time = "", price = "", href = "", startDate = "", endDate = "", tel = ""; int capacity = 1, lId = -1, tId = -1, cId = -1; LocalDateTime deadline = LocalDateTime.now(); @@ -88,6 +88,10 @@ public void scrapNowon() throws CustomException { if (!cols.get(cols.size() - 1).getText().trim().equals("수강신청")) continue; log.info("수강신청 여부 통과"); + WebElement telInfo = driver.findElement(By.xpath("/html/body/footer/div[2]/div[2]/address/a[1]")); + tel = telInfo.getText(); + log.info("tel = {}", tel); + System.out.println("2222"); for (int j = 3; j < cols.size(); j++) { String content = cols.get(j).getText(); diff --git a/src/main/java/zerobase/sijak/service/scrap/SongpaScrapService.java b/src/main/java/zerobase/sijak/service/scrap/SongpaScrapService.java index a1708ed..4c91349 100644 --- a/src/main/java/zerobase/sijak/service/scrap/SongpaScrapService.java +++ b/src/main/java/zerobase/sijak/service/scrap/SongpaScrapService.java @@ -11,6 +11,7 @@ import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import zerobase.sijak.exception.Code; @@ -41,10 +42,10 @@ public class SongpaScrapService { private final CareerRepository careerRepository; private final EducateRepository educateRepository; - //@Scheduled(fixedRate = 10000000) + @Scheduled(fixedRate = 10000000) public void scrapSongpa() throws CustomException { try { - String name = "", time = "", href = "", price = "", dayOfWeek = "", location = ""; + String name = "", time = "", href = "", price = "", dayOfWeek = "", location = "", tel = ""; int capacity = 1, lId = -1, tId = -1, cId = -1; WebDriverManager.chromedriver().setup(); @@ -68,9 +69,14 @@ public void scrapSongpa() throws CustomException { String url = String.format(SONGPA_URL, idx); log.info("url : {} ", url); driver.get(url); - WebElement specificTable = driver.findElement(By.xpath("//*[@id=\"mainsection\"]/div/div/div/div/div[3]/table")); WebElement specificTbody = specificTable.findElement(By.tagName("tbody")); + + WebElement telInfo = driver.findElement(By.xpath("//*[@id=\"pbottom\"]")); + String[] temp = telInfo.getText().split("\n")[1].split(" "); + tel = temp[7] + "-" + temp[8] + "-" + temp[9]; + log.info("tel: {}", tel); + // 읽을 Tbody가 없다면 -> 크롤링 종료 if (specificTbody.getText().isEmpty()) { System.out.println("specificTbody is empty"); @@ -139,6 +145,7 @@ public void scrapSongpa() throws CustomException { .centerName("송파여성문화회관") .capacity(capacity) .division("정기 클래스") + .tel(tel) .status(true) .endDate("") .total(12)