-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yennanliu/Scraping-dev-001-code-refine
Scraping-dev-001-code-refine
- Loading branch information
Showing
12 changed files
with
863 additions
and
628 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
57 changes: 30 additions & 27 deletions
57
dev_projects/ScrapingService/src/main/java/com/yen/scrpe/Task/ScrapeTaskFactory.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 |
---|---|---|
@@ -1,49 +1,52 @@ | ||
package com.yen.scrpe.Task; | ||
|
||
import com.yen.scrpe.service.BaseScrapeService; | ||
|
||
import java.io.IOException; | ||
|
||
/** Factory for constructing scraping job | ||
/** | ||
* Factory for constructing scraping job | ||
* | ||
* Design pattern : Factory | ||
* <p>Design pattern : Factory | ||
* | ||
* - https://www.runoob.com/design-pattern/factory-pattern.html | ||
* <p>- https://www.runoob.com/design-pattern/factory-pattern.html | ||
*/ | ||
public class ScrapeTaskFactory { | ||
|
||
// attr | ||
private BaseScrapeService scrapeService; | ||
// attr | ||
private BaseScrapeService scrapeService; | ||
|
||
private BaseScrapeTask scrapeTask; | ||
private BaseScrapeTask scrapeTask; | ||
|
||
private String jobName; | ||
private String jobName; | ||
|
||
private int limit; | ||
private int limit; | ||
|
||
// constructor | ||
public ScrapeTaskFactory(){ | ||
// constructor | ||
public ScrapeTaskFactory() {} | ||
|
||
} | ||
public ScrapeTaskFactory( | ||
BaseScrapeService scrapeService, BaseScrapeTask scrapeTask, Integer limit) { | ||
|
||
public ScrapeTaskFactory(BaseScrapeService scrapeService, BaseScrapeTask scrapeTask, Integer limit){ | ||
this.scrapeService = scrapeService; | ||
this.scrapeTask = scrapeTask; | ||
this.limit = limit; | ||
} | ||
|
||
this.scrapeService = scrapeService; | ||
this.scrapeTask = scrapeTask; | ||
this.limit = limit; | ||
} | ||
// method | ||
public void run() throws IOException, InterruptedException { | ||
|
||
// method | ||
public void run() throws IOException { | ||
// this.jobName = "PokemonCollectTask"; | ||
// System.out.println("this.jobName = " + this.jobName); | ||
|
||
switch (this.jobName){ | ||
case "PokemonCollectTask": | ||
// pokemonCollectTask.run(LIMIT); | ||
this.scrapeTask.run(this.limit); | ||
default: | ||
throw new RuntimeException("Not a valid task name :" + this.scrapeTask.toString()); | ||
this.scrapeTask.run(this.limit); | ||
|
||
} | ||
} | ||
// switch (this.jobName) { | ||
// case "PokemonCollectTask": | ||
// // pokemonCollectTask.run(LIMIT); | ||
// this.scrapeTask.run(this.limit); | ||
// default: | ||
// throw new RuntimeException("Not a valid task name :" + this.scrapeTask.toString()); | ||
// } | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
dev_projects/ScrapingService/src/main/java/com/yen/scrpe/Task/ScrapeTaskFactory2.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,44 @@ | ||
package com.yen.scrpe.Task; | ||
|
||
import com.yen.scrpe.Task.PokemonCollectTask; | ||
import com.yen.scrpe.model.PokemonProduct; | ||
import com.yen.scrpe.service.ScrapeServiceMultiThreadV2Gpt; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class ScrapeTaskFactory2 { | ||
|
||
private final ScrapeServiceMultiThreadV2Gpt scrapeService; | ||
private final PokemonCollectTask pokemonCollectTask; | ||
private final int limit; | ||
|
||
public ScrapeTaskFactory2(ScrapeServiceMultiThreadV2Gpt scrapeService, PokemonCollectTask pokemonCollectTask, int limit) { | ||
this.scrapeService = scrapeService; | ||
this.pokemonCollectTask = pokemonCollectTask; | ||
this.limit = limit; | ||
} | ||
|
||
public void run() throws IOException, InterruptedException { | ||
List<PokemonProduct> pokemonProducts = new LinkedList<>(); | ||
Set<String> pagesDiscovered = new HashSet<>(); | ||
List<String> pagesToScrape = new LinkedList<>(); | ||
pagesToScrape.add("https://scrapeme.live/shop"); | ||
|
||
//pokemonCollectTask.run(pokemonProducts, pagesDiscovered, pagesToScrape, limit); | ||
pokemonCollectTask.run(limit); | ||
|
||
System.out.println("Scraping completed."); | ||
System.out.println("Collected Pokemon Products:"); | ||
for (PokemonProduct product : pokemonProducts) { | ||
System.out.println(product); | ||
} | ||
|
||
// Ensure the executor service is shut down | ||
scrapeService.shutdown(); | ||
} | ||
|
||
} |
Oops, something went wrong.