データを解析する必要があるウェブサイトがあります。私はキーワードの結果によっていくつかの検索を取得する必要があります。ただし、すべてのフィールドが製品のプレビューに表示されるわけではありません。これらのフィールド(商品の色、説明、古い価格)は、各商品ページからのみ拾い読みすることができます。製品ページのURLは次のようになりますhttps://www.aboutyou.de/p/new-look/basecap-in-satin-optik-3649077 SIは一般的な方法でそれを呼び出す方法を知らないので、各製品を調べる必要はありません。私はプロジェクトの名前とブランドを知ることができますが、URLを構築する方法はわかりません。すべての文字を大文字にし、単語間にダッシュを入れます。 私はこのような方法でブランド名と製品名を得ることができます:Satin-OptikのNEW LOOK Basecap。製品ページに接続するurls Jsoup
どのように各製品のURLを定義できますか?
String url = "https://www.aboutyou.de/frauen/accessoires/huete-und-muetzen/caps";
Document doc = Jsoup.connect(url).get();
System.out.println("Title: " + doc.title());
String mainPath = "section.layout_11glwo1-o_O-stretchLayout_1jug6qr > " +
"div.content_1jug6qr > " +
"div.container > " +
"div.mainContent_10ejhcu > " +
"div.productStream_6k751k > " +
"div > " +
"div.wrapper_8yay2a > " +
"div.col-sm-6.col-md-4 > " +
"div.wrapper_1eu800j > " +
"div > " +
"div.categoryTileWrapper_e296pg";
String searchPath = mainPath + " > a.anchor_wgmchy > " +
"div.details_197iil9 > " +
"div.meta_1ihynio";
String linksPath = mainPath + " > a.anchor_wgmchy";
String brandPath = mainPath + " > a.anchor_wgmchy > " +
"div.details_197iil9 > " +
"div.meta_1ihynio > " +
"div.description_ya0ltb > " +
"strong.brand_ke66rm";
Elements result = doc.body().select("main#app");
for(Element element : result) {
Elements products = element.select(searchPath);
Elements links = element.select(linksPath);
Elements brands = element.select(brandPath);
for(Element product : products){
System.out.println(product.text());
}
String[] linksText = null;
for(Element link : links){
String linkHref = link.attr("href");
String linkText = link.text();
linksText = linkHref.split("[\\-]");
String id = linksText[linksText.length-1];
System.out.println("id: " + id);
System.out.print("link attr:" + linkHref + ", ");
}
System.out.print("\nbrands" + brands.text());
}
はたぶん、そのためのいくつかのライブラリがあります。ここでは
は、私がこれまで持っているコードのですか?私はどんなアドバイスにも感謝しています!
しかし、私も製品の色と説明が必要です。私は質問 – Cassie
でそれを言及しました。@Cassie実際にサブクエリーが必要です。更新されたコードを見てください。 –
@Cassieはこれで解決しましたか?その後、回答を受け入れるか、フォローアップのコメントを投稿してください。 –