-
Notifications
You must be signed in to change notification settings - Fork 1
FetchData Class
The FetchData class is part of the services package (package org.example.globalgoodsindex.services) and is
responsible for scraping data from external source: Numbeo - a website that
provides cost-of-living information. It contains methods to scrape salary data and product price data for different
countries. These methods use Jsoup for HTML parsing and data extraction.
The class provides static methods that return the scraped data in well-structured formats, ready for further processing or display in the application.
Scrapes the average monthly net salary (after tax) for countries from the Numbeo website and returns the data sorted alphabetically by country.
- Connects to
the Numbeo website using
Jsoupand retrieves salary data from a table. - Extracts the country name and salary, parsing the salary as a double after removing commas.
- Invalid salary entries are skipped, and an error message is logged.
- The list of
Salaryobjects is sorted alphabetically by country name before returning.
- A
List<Salary>of countries and their corresponding salaries, sorted alphabetically. - Returns
nullif there's a connection issue or invalid data.
List<Salary> salariesData = FetchData.scrapeSalaries();- Logs errors for invalid salary formats or connection issues.
Scrapes product price data for various countries from the Numbeo website and returns the data sorted alphabetically by country.
- Connects to the Numbeo website
using
Jsoupand constructs a URL based on theitemIdvalues from theGoodsenum, which lists the available goods. - Extracts product names (headers) and their prices for each country from the table.
- If the price is missing, it is replaced with a placeholder ("-"). Special characters are removed from the headers for consistency (e.g., spaces are replaced with underscores).
- The data is sorted alphabetically by country name before returning it as a list of lists.
- A
List<List<String>>containing the product column headers and their prices for each country, sorted alphabetically by country name. - Returns
nullif there's a connection issue or invalid data.
List<List<String>> productsData = FetchData.scrapeProducts();- Logs errors for connection issues, missing or incomplete product rows, and any parsing errors.