Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selenium 오류 수정 #30

Merged
merged 6 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
java-version: 17
distribution: 'temurin'

- name: selenium을 위한 chrome 드라이버 설치
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
- name: Give permission for Gradle
run: chmod +x gradlew

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/gdsc/goodeat/domain/FoodScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
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;

@Component
public class FoodScraper {

private static final String TASTEATLAS_URL = "https://www.tasteatlas.com/";
private static final String FOOD_IMG_NOT_FOUND_URL = "https://storage.googleapis.com/goodeat/food_image_not_found.jpg";
private static final Duration DEFAULT_IMPLICIT_WAIT_DURATION = Duration.ofSeconds(5);
Expand All @@ -26,12 +30,13 @@ public class FoodScraper {

private final WebDriver driver;


public FoodScraper() {
this.driver = new ChromeDriver();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
this.driver = new ChromeDriver(options);
}

public List<FoodInfo> scrape(List<String> foodList) {
public List<FoodInfo> scrape(final List<String> foodList) {
List<FoodInfo> foodInfoList = new ArrayList<>();

for (String foodName : foodList) {
Expand Down Expand Up @@ -94,6 +99,7 @@ private FoodInfo extractFoodInfo() {
@Data
@AllArgsConstructor
public static class FoodInfo {

private String image;
private String description;

Expand Down
Loading