WebScrapping on a Schedule
Spring Boot application for web scraping with JSoup
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@SpringBootApplication
@EnableScheduling
public class WebScrapingApplication {
public static void main(String[] args) {
SpringApplication.run(WebScrapingApplication.class, args);
}
@Service
public static class WebScrapingService {
@Scheduled(fixedRate = 10000) // Runs every 10 seconds
public void scrapeWebsite() {
try {
Document doc = Jsoup.connect("https://example.com").get();
String title = doc.title();
System.out.println("Website Title: " + title);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}TL;DR:
Last updated