• 实践清洗爬取的热词数据。
  • 存储清洗后的数据到本地文件。
 
def save_cleaned_data(hot_words, file_path):
    cleaned_words = [clean_text(word) for word in hot_words]
    with open(file_path, 'w') as f:
        for word in cleaned_words:
            f.write(word + '\n')

hot_words = fetch_hot_words("https://example.com/hot-words")
save_cleaned_data(hot_words, "cleaned_hot_words.txt")