initial commit

This commit is contained in:
Σlie *
2026-02-27 18:16:57 +01:00
commit 2061cc29ff
9 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package fr.tetelie.crawler;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class Crawler {
public static void main(String[] args) {
String url = "https://www.amazon.fr/Victool-temp%C3%A9rature-professionnel-r%C3%A9paration-%C3%A9lectronique/dp/B0FP2D7TBY/?_encoding=UTF8&pd_rd_w=UWXHj&content-id=amzn1.sym.5633189b-a269-4b24-8a80-52a48568a326%3Aamzn1.symc.752cde0b-d2ce-4cce-9121-769ea438869e&pf_rd_p=5633189b-a269-4b24-8a80-52a48568a326&pf_rd_r=G56TKFERTQ9WS62C7WY4&pd_rd_wg=mtTBQ&pd_rd_r=519dfa29-c58c-41b3-89ca-4d01e27bfc2e&ref_=pd_hp_d_atf_ci_mcx_mr_ca_hp_atf_d";
try {
// IMPORTANT : Amazon bloque les requêtes sans "User-Agent"
Document doc = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
.get();
// On cherche la classe .a-price-whole
Element priceElement = doc.selectFirst(".a-price-whole");
Element fractionElement = doc.selectFirst(".a-price-fraction");
if (priceElement != null) {
String price = priceElement.text();
} else {
System.out.println("Prix non trouvé");
}
if(fractionElement != null) {
String fraction = fractionElement.text();
}else{
System.out.println("Fraction non trouvé");
}
if(fractionElement != null && priceElement != null) {
System.out.println("Le prix est de: " + priceElement.text() + fractionElement.text());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}