python 读写操作excel表

def sync_goods_producer(path):
    # doc_data = pandas.read_excel(path, skiprows=44, engine='xlrd')
    doc_data = pandas.read_excel(path,engine='xlrd')
    doc_data = doc_data.where(doc_data.notnull(), '')
    columns = list(doc_data.columns)
    with redis_connect_online.pipeline() as pipe:
        for rank,doc in enumerate(doc_data.values):
            goods_task = dict(zip(columns, doc))
            goods_task['file_name'] = path
            goods_task['rank'] = rank +1
            try:
                url_params = UrlHelper.url_parse(goods_task['商品链接'])
            except KeyError:
                continue
            goods_id=url_params.get('id')
            goods__detail_task = {
                "sta_date": time.strftime("%Y-%m-%d"),
                "goods_id": goods_id,
                "url": f"https://ec.snssdk.com/product/fxgajaxstaticitem?b_type_new=0&device_id=0&is_outside=1&id={goods_id}&preview=0",
            }
            pipe.sadd("douyin_goods_detail:start_urls", json.dumps(goods__detail_task))
            pipe.sadd("feigua_goods_rank", json.dumps(goods_task))
        pipe.execute()
posted @ 2022-07-22 17:19  莫贞俊晗  阅读(83)  评论(0编辑  收藏  举报