主頁 > 知識庫 > Python爬蟲分析微博熱搜關(guān)鍵詞的實(shí)現(xiàn)代碼

Python爬蟲分析微博熱搜關(guān)鍵詞的實(shí)現(xiàn)代碼

熱門標(biāo)簽:外呼系統(tǒng)前面有錄音播放嗎 400電話辦理費(fèi)用收費(fèi) 千呼ai電話機(jī)器人免費(fèi) 柳州正規(guī)電銷機(jī)器人收費(fèi) 申請辦個400電話號碼 鎮(zhèn)江人工外呼系統(tǒng)供應(yīng)商 深圳網(wǎng)絡(luò)外呼系統(tǒng)代理商 騰訊地圖標(biāo)注有什么版本 高德地圖標(biāo)注字母

1,使用到的第三方庫
requests
BeautifulSoup 美味湯
worldcloud 詞云
jieba 中文分詞
matplotlib 繪圖
2,代碼實(shí)現(xiàn)部分

import requests
import wordcloud
import jieba
from bs4 import BeautifulSoup
from matplotlib import pyplot as plt
from pylab import mpl

#設(shè)置字體
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False

url = 'https://s.weibo.com/top/summary?Refer=top_hottopnav=1wvr=6'

try:
  #獲取數(shù)據(jù)
  r = requests.get(url)
  r.raise_for_status()
  r.encoding = r.apparent_encoding
  soup = BeautifulSoup(r.text,'html.parser')
  data = soup.find_all('a')
  d_list = []
  for item in data:
    d_list.append(item.text)
  words = d_list[4:-11:]
  #中文分詞
  result = list(jieba.cut(words[0]))
  for word in words[1::]:
    result.extend(jieba.cut(word))
  redata = []
  for it in result:
    if len(it) = 1:
      continue
    else:
      redata.append(it)
  result_str = ' '.join(redata)
  #輸出詞云圖
  font = r'C:\Windows\Fonts\simhei.ttf'
  w = wordcloud.WordCloud(font_path=font,width=600,height=400)
  w.generate(result_str)
  w.to_file('微博熱搜關(guān)鍵詞詞云.png')
  key = list(set(redata))
  x,y = [],[]
  #篩選數(shù)據(jù)
  for st in key:
    count = redata.count(st)
    if count = 1:
      continue
    else:
      x.append(st)
      y.append(count)
  x.sort()
  y.sort()
  #繪制結(jié)果圖
  plt.plot(x,y)
  plt.show()
except Exception as e:
  print(e)

 

3,運(yùn)行結(jié)果


到此這篇關(guān)于Python爬蟲分析微博熱搜關(guān)鍵詞的文章就介紹到這了,更多相關(guān)Python爬蟲微博熱搜內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python一些性能分析的技巧
  • Python性能分析工具py-spy原理用法解析
  • Python內(nèi)置類型性能分析過程實(shí)例
  • Python性能分析工具Profile使用實(shí)例
  • cProfile Python性能分析工具使用詳解
  • Python中判斷子串存在的性能比較及分析總結(jié)
  • 使用pycallgraph分析python代碼函數(shù)調(diào)用流程以及框架解析
  • 使用bandit對目標(biāo)python代碼進(jìn)行安全函數(shù)掃描的案例分析
  • python中delattr刪除對象方法的代碼分析
  • python3中確保枚舉值代碼分析
  • python如何做代碼性能分析

標(biāo)簽:烏蘭察布 哈爾濱 合肥 海南 平頂山 烏蘭察布 郴州 大慶

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python爬蟲分析微博熱搜關(guān)鍵詞的實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  Python,爬蟲,分析,微博,熱搜,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python爬蟲分析微博熱搜關(guān)鍵詞的實(shí)現(xiàn)代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于Python爬蟲分析微博熱搜關(guān)鍵詞的實(shí)現(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章