ValueError:基数为10的int()的无效文字:'12,652'

时间:2016-03-12 14:26:59

标签: python-2.7 web-scraping

我试图获得特定产品的评论次数

代码是:

total_reviews = soup.find("div", {"class": "feature"}).findNext(
    "span", {"id": "acrCustomerReviewText"}).string
x = ''
for number in total_reviews:
    if number == ' ':
        break
    else:
        x = x + number

num_reviews =int(x)

1 个答案:

答案 0 :(得分:0)

使用str.replace()替换逗号为空字符串:

num_reviews = int(x.replace(",", ""))