示例#1
0
def get_mi10_data_from_sn(browser: Chrome):
    for sn_shop in Shop.select().where(Shop.source == '苏宁'):
        print(f'------打开当前苏宁商品链接: {sn_shop.url}------')
        browser.get(sn_shop.url)
        # 获取所有SKU和评论统计
        get_sn_sku_and_comment_summary_from_api(browser, sn_shop)

        # 获取默认排序评论, 并遍历所有SKU
        print('------开始获取默认排序评论------')
        switch_to_sn_default_comments_page(browser, sn_shop.url)
        get_sn_comments(browser, sn_shop)

        # 轮询各个SKU的商品页面
        print('------SKU轮询开始------')
        for current_sku in sn_shop.sku:
            print(f'------本轮SKU: {current_sku.sku}------')
            current_sku_url = current_sku.url_prefix + current_sku.shop_code + '/' + current_sku.sku + '.html'
            print(f'------正在打开当前SKU链接: {current_sku_url}------')
            browser.get(current_sku_url)

            print('------开始获取当前SKU默认排序评论------')
            switch_to_sn_sku_comments_page(browser, current_sku_url)
            get_sn_comments(browser, sn_shop, sku_mode=True)

    # 数据汇总后计算最终好评率
    calculate_jd_and_sn_good_rate(
        CommentSummary.select().where(CommentSummary.source == '苏宁'))
    calculate_jd_and_sn_good_rate(
        ModelSummary.select().where(ModelSummary.source == '苏宁'))
    print('------苏宁平台数据获取完成------')
示例#2
0
def get_mi10_data_from_jd(browser: Chrome):
    for jd_shop in Shop.select().where(Shop.source == '京东'):
        print(f'------打开当前京东商品链接: {jd_shop.url}------')
        browser.get(jd_shop.url)  # 打开商品页面
        # 获取已上架SKU
        get_jd_sku_from_api(browser, jd_shop)

        # 获取默认推荐排序评论和默认时间排序评论, 并遍历所有SKU
        print('------开始获取默认推荐排序评论------')
        switch_to_jd_default_comments_page(browser, jd_shop.url)  # 打开评论默认页面
        get_jd_comments(browser, jd_shop, get_sku=True,
                        summary=True)  # 从全部评价标签获取评论和统计信息

        print('------开始获取默认时间排序评论------')
        switch_to_jd_default_comments_page(browser, jd_shop.url)
        switch_to_jd_time_sort(browser)  # 切换到时间排序
        get_jd_comments(browser, jd_shop, get_sku=True)  # 从全部评价标签获取评论

        # 轮询各个SKU的商品页面
        print('------SKU轮询开始------')
        for current_sku in jd_shop.sku:
            print(f'------本轮SKU: {current_sku.sku}------')
            current_sku_url = current_sku.url_prefix + current_sku.sku + '.html'
            print(f'------正在打开当前SKU链接: {current_sku_url}------')
            browser.get(current_sku_url)

            print('------开始获取当前SKU推荐排序评论------')
            switch_to_jd_sku_comments_page(browser, current_sku_url)
            get_jd_comments(browser, jd_shop, sku_mode=True,
                            summary=True)  # 从全部评价标签获取评论和统计信息

            print('------开始获取当前SKU时间排序评论------')
            switch_to_jd_sku_comments_page(browser, current_sku_url)
            switch_to_jd_time_sort(browser)  # 切换到时间排序
            get_jd_comments(browser, jd_shop, sku_mode=True)  # 从全部评价标签获取评论

    # 数据汇总后计算最终好评率
    calculate_jd_and_sn_good_rate(
        CommentSummary.select().where(CommentSummary.source == '京东'))
    calculate_jd_and_sn_good_rate(
        ModelSummary.select().where(ModelSummary.source == '京东'))
    print('------京东平台数据获取完成------')