-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 무신사, 29cm 크롤링 로직 추가 & 공통 크롤링 로직 리팩토링 #59
- Loading branch information
1 parent
07f7cfb
commit 444b1a3
Showing
9 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Infrastructure/src/main/java/tify/server/infrastructure/outer/crawling/MusinsaCrawl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package tify.server.infrastructure.outer.crawling; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.UnhandledAlertException; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.springframework.stereotype.Component; | ||
import tify.server.infrastructure.exception.FeignException; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MusinsaCrawl { | ||
private WebDriver driver; | ||
|
||
public String process(String url) { | ||
System.setProperty( | ||
"webdriver.chrome.driver", | ||
"/Users/sehwan/Downloads/chromedriver-mac-arm64/chromedriver"); | ||
|
||
ChromeOptions options = new ChromeOptions(); | ||
options.addArguments("--remote-allow-origins=*"); | ||
|
||
driver = new ChromeDriver(options); | ||
|
||
String imgSrc = ""; | ||
|
||
try { | ||
imgSrc = getDataList(url); | ||
} catch (InterruptedException e) { | ||
throw FeignException.EXCEPTION; | ||
} catch (UnhandledAlertException e) { | ||
log.info("유효하지 않은 url : {}", url); | ||
} | ||
|
||
driver.close(); | ||
driver.quit(); | ||
|
||
return imgSrc; | ||
} | ||
|
||
private String getDataList(String url) throws InterruptedException { | ||
driver.get(url); | ||
Thread.sleep(1000); | ||
WebElement element = driver.findElement(By.id("detail_bigimg")).findElement(By.className("product-img")).findElement(By.id("bigimg")); | ||
System.out.println(element.toString()); | ||
return element.getAttribute("src"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Infrastructure/src/main/java/tify/server/infrastructure/outer/crawling/TwentyNineCrawl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package tify.server.infrastructure.outer.crawling; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.UnhandledAlertException; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.springframework.stereotype.Component; | ||
import tify.server.infrastructure.exception.FeignException; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TwentyNineCrawl { | ||
private WebDriver driver; | ||
|
||
public String process(String url) { | ||
System.setProperty( | ||
"webdriver.chrome.driver", | ||
"/Users/sehwan/Downloads/chromedriver-mac-arm64/chromedriver"); | ||
|
||
ChromeOptions options = new ChromeOptions(); | ||
options.addArguments("--remote-allow-origins=*"); | ||
|
||
driver = new ChromeDriver(options); | ||
|
||
String imgSrc = ""; | ||
|
||
try { | ||
imgSrc = getDataList(url); | ||
} catch (InterruptedException e) { | ||
// throw FeignException.EXCEPTION; | ||
log.info("에러 발생 ㅠㅠ"); | ||
} catch (UnhandledAlertException e) { | ||
log.info("유효하지 않은 url : {}", url); | ||
} finally { | ||
driver.close(); | ||
driver.quit(); | ||
|
||
return imgSrc; | ||
} | ||
} | ||
|
||
private String getDataList(String url) throws InterruptedException { | ||
driver.get(url); | ||
Thread.sleep(1000); | ||
if (!driver.findElements(By.cssSelector(".css-12qah06.ewptmlp5")).isEmpty()) { | ||
WebElement element = driver.findElements(By.cssSelector(".css-12qah06.ewptmlp5")).get(0); | ||
System.out.println(element.toString()); | ||
return element.getAttribute("src"); | ||
} | ||
return null; | ||
} | ||
} |