Closed mohammad-fahs closed 2 months ago
@mohammad-fahs Hello Mohammad, I have finished Task 2 for Scraping laptops from ExpertZone Website ("https://ezonelb.com/"), where I scraped the laptop's title, Image URL, Category, price and availability.
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component;
import java.util.List;
@Component public class WebScraper implements CommandLineRunner {
@Autowired
private ScraperService scraperService;
@Override
public void run(String... args) throws Exception {
String url = "https://ezonelb.com/product-category/desktop-laptop-vr/gaming-high-end-laptop/";
List<Laptop> laptops = scraperService.scrapeLaptops(url);
for (Laptop laptop : laptops) {
System.out.println(laptop);
}
}
}
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: