Skip to content

Commit

Permalink
[Refactor] 문화센터 전화번호 컬럼 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Bumnote committed Nov 1, 2024
1 parent 08d21b0 commit 69cf3ab
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class QLecture extends EntityPathBase<Lecture> {

public final ListPath<Teacher, QTeacher> teachers = this.<Teacher, QTeacher>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");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/zerobase/sijak/persist/domain/Lecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +30,8 @@ public class Lecture {
@Size(max = 1000)
private String description;

private String tel;

private String price;

@OneToMany(mappedBy = "lecture")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -148,6 +151,7 @@ public void scrapNowon() throws CustomException {
.certification("")
.dayOfWeek("")
.target("")
.tel(tel)
.textBookName("")
.textBookPrice("")
.thumbnail("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<WebElement> 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");
Expand Down Expand Up @@ -151,6 +154,7 @@ public void scrapMapo() throws CustomException {
.division("정기 클래스")
.latitude(37.556445)
.need("")
.tel(tel)
.textBookName("")
.textBookPrice("")
.thumbnail("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/zerobase/sijak/service/scrap/SongpaScrapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand Down Expand Up @@ -139,6 +145,7 @@ public void scrapSongpa() throws CustomException {
.centerName("송파여성문화회관")
.capacity(capacity)
.division("정기 클래스")
.tel(tel)
.status(true)
.endDate("")
.total(12)
Expand Down

0 comments on commit 69cf3ab

Please sign in to comment.