私は現在、大量のデータを求めて amazon をスクレイピングしようとしています。私は jsoup を使用してこれを行っており、すべてが非常にスムーズに進んでいますが、何らかの理由で、新製品を販売している現在の売り手の数を引き出す方法がわかりません。
スクレイピングしている URL の例を次に示します: http://www.amazon.com/dp/B006L7KIWG
以下から「39 new」を抽出したい:
<div id="secondaryUsedAndNew" class="mbcOlp">
<div class="mbcOlpLink">
<a class="buyAction" href="/gp/offer-listing/B006L7KIWG/ref=dp_olp_new_mbc?ie=UTF8&condition=new">
39 new
</a> from
<span class="price">$60.00</span>
</div>
</div>
このプロジェクトは私が初めて jsoup を使用したため、コーディングは少しわかりにくいかもしれませんが、私が試したことのいくつかを以下に示します。
String asinPage = "http://www.amazon.com/dp/" + getAsin();
try {
Document document = Jsoup.connect(asinPage).timeout(timeout).get();
.....
//get new sellers try one
Elements links = document.select("a[href]");
for (Element link : links) {
// System.out.println("Span olp:"+link.text());
String code = link.attr("abs:href");
String label = trim(link.text(), 35);
if (label.contains("new")) {
System.out.println(label + " : " + code);
}
}
//get new sellers try one
Elements links = document.select("div.mbcOlpLink");
for (Element link : links) {
// System.out.println("Span olp:"+link.text());
}
//about a million other failed attempts that you'll just have to take my word on.
ページで必要な他のすべてをスクレイピングすると成功しましたが、何らかの理由でこの特定の要素が苦痛であり、どんな助けも素晴らしいでしょう! みんなありがとう!