這是我在那裏我試圖獲取數據flipkartIndexError:列表索引超出範圍,而使用BS4
鏈接和代碼的一部分:
<div class="toolbar-wrap line section">
<div class="ratings-reviews-wrap">
<div itemprop="aggregateRating" itemscope="" itemtype="http://schema.org/AggregateRating" class="ratings-reviews line omniture-field">
<div class="ratings">
<meta itemprop="ratingValue" content="1">
<div class="fk-stars" title="1 stars">
<span class="unfilled">★★★★★</span>
<span class="rating filled" style="width:20%">
★★★★★
</span>
</div>
<div class="count">
<span itemprop="ratingCount">2</span>
</div>
</div>
</div>
</div>
</div>
這裏我要取從1星title= 1 star
和2從<span itemprop="ratingCount">2</span>
我試試下面的代碼
x = link_soup.find_all("div",class_='fk-stars')[0].get('title')
print x, " product_star"
y = link_soup.find_all("span",itemprop="ratingCount")[0].string.strip()
print y
但它給
IndexError: list index out of range
您的代碼工作正常,我 – gtlambert
這就是我試圖湯http://www.flipkart.com/kanika-women-s-nighty/p/itmed2yqzdgqgz3q?pid=NDNED2YQU9HPESEA&al=FvCq1Xh5FyMN11cjuYgL6MldugMWZuE7svdkPtTGUY6%2F3Fk9x0T1uX3Tym%鏈接2F%2F6pAalZzKUG0RUT0%3D&ref = L%3A9146140901050108837&srno = p_14&query = nighty&otracker = from-search – YAM
對我來說也適用。有沒有涉及的藏品?也許你正在迭代一個div列表? – siphr