【发布时间】:2019-11-24 15:34:47
【问题描述】:
这是网站的html代码:
<div class="list_item">
<a href="/p/fifa-19-ps4" title="Fifa 19... on PS4">
<img src="/uploads/products/42376/42376_xsm.jpg?v=MjAxOS0xMS0yNCAxNToxMjowMw==" alt="Fifa 19... on PS4" title="Fifa 19... on PS4" border="0">
<div class="product_name">Fifa 19...</div>
<span>£9.99</span>
</a>
<a href="/p/fifa-19-ps4" class="button in_stock" title="Fifa 19 on PS4">View Product</a>
</div>
我使用 JSoup 的代码:
Document doc = Jsoup.connect("https://www.simplygames.com/search?keywords=" + itemName).get();
//Get all products on the page
Elements products = doc.select("list_item");
//work through the products using for loop
for(int i = 0; i<products.size(); ++i){
//get the product description
Elements description = products.get(i).select("product_name");
//get the products price
Elements price = products.get(i).select("");
//Ouput web scraped data
System.out.println("DESCRIPTION: " + description.text() + "; PRICE: " + price.text());
}
我在从没有像 div 这样的类的 span 元素中抓取价格时遇到问题。我该怎么做?
【问题讨论】: