import requests
import json


def get_comments(product_id):
    """
    获取商品的评论

    :param product_id: int 商品的id
    :return: 商品的所有评论列表
    """
    comment_list = []
    comment_url = "https://item.fenqile.com/item/query_product_comment.json?product_id={product_id}&page={page}"
    page = 0
    flag = True
    while flag:
        page += 1
        url = comment_url.format(product_id=product_id, page=page)
        res = requests.get(url)
        data = json.loads(res.content.decode("utf-8"))
        comments = data.get("comment_list")
        total_page = data.get("total_page")
        comment_list += comments
        if  page == int(total_page):
            flag = False
    return comment_list