12345678910111213141516 |
- import pandas as pd
- def get_one_page_excel(weibo_content_str, weibo_mid_str, weibo_time_str, weibo_like_count, weibo_comment_count, length):
- one_page_data = []
- for i in range(0, length):
- one_piece_data = (
- weibo_mid_str[i], weibo_time_str[i], weibo_content_str[i], weibo_like_count[i], weibo_comment_count[i])
- column_name = ('文章ID', '发文时间', '文章内容', '点赞数', '评论数')
- one_page_data.append(dict(zip(column_name, one_piece_data)))
- return one_page_data
- def save_to_excel(all_data, keyword, date):
- df = pd.DataFrame(all_data)
- df.to_excel('微博爬取内容-' + keyword + '-' + date + '.xlsx', index=False)
|