Closed mohammad-fahs closed 2 months ago
Fleurs de la Sagesse is an online store specializing in a variety of plants, including green plants, which can be used for decoration or gifting.
Below are the screenshots showing the output of the scraped data from the application:
![Scraped Data Output 1]( )
![Scraped Data Output 2](
)
And this is the java code
package com.jana.web_scaper;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Scanner;
@Component
public class ScrapingApplication implements CommandLineRunner {
ScrapingService scrapingService = new ScrapingService();
@Override
public void run(String... args) throws Exception {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Enter a Link to scrape or exit to stop: ");
String link = scan.nextLine().trim();
if (link.equalsIgnoreCase("exit")) {
System.out.println("Exiting the application. Goodbye!");
break;
}
List<Plants> plantsList = scrapingService.Scrape(link);
for (Plants plants : plantsList) {
System.out.println(plants.toString());
}
}
scan.close();
}
}
Task 2 :
Objective:
In this task, you will initialize a new Spring Boot project, add the JSoup dependency, and write a simple Java program to scrape data from a website of your choice. The goal is to get hands-on experience with setting up a Spring Boot project, using an external library (JSoup), and applying web scraping techniques.
Instructions:
com.yourname
web-scraper
Web Scraper
com.yourname.webscraper
Spring Web
dependency (to allow adding more features later).pom.xml
file in the root directory of your project.<dependencies>
tag:pom.xml
file and allow IntelliJ to update the Maven project to download the JSoup library.com.yourname.webscraper
package that implements theCommandLineRunner
interface.run
method, use JSoup to connect to the website you chose and scrape the data.Submit Your Work:
CommandLineRunner
.Resources that can help: