save_data_to_excel.py 729 B

12345678910111213141516
  1. import pandas as pd
  2. def get_one_page_excel(weibo_content_str, weibo_mid_str, weibo_time_str, weibo_like_count, weibo_comment_count, length):
  3. one_page_data = []
  4. for i in range(0, length):
  5. one_piece_data = (
  6. weibo_mid_str[i], weibo_time_str[i], weibo_content_str[i], weibo_like_count[i], weibo_comment_count[i])
  7. column_name = ('文章ID', '发文时间', '文章内容', '点赞数', '评论数')
  8. one_page_data.append(dict(zip(column_name, one_piece_data)))
  9. return one_page_data
  10. def save_to_excel(all_data, keyword, date_begin, date_end):
  11. df = pd.DataFrame(all_data)
  12. df.to_excel('微博爬取内容-' + keyword + '-' + date_begin + '-' + date_end + '.xlsx', index=False)