最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
使用python怎么爬取微博的熱搜數(shù)據(jù)-創(chuàng)新互聯(lián)

使用python怎么爬取微博的熱搜數(shù)據(jù)?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括八步網(wǎng)站建設(shè)、八步網(wǎng)站制作、八步網(wǎng)頁(yè)制作以及八步網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,八步網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到八步省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

主要用到requests和bf4兩個(gè)庫(kù)
將獲得的信息保存在d://hotsearch.txt下

import requests;
import bs4
mylist=[]
r = requests.get(url='https://s.weibo.com/top/summary?Refer=top_hot&topnav=1&wvr=6',timeout=10)
print(r.status_code) # 獲取返回狀態(tài)
r.encoding=r.apparent_encoding
demo = r.text
from bs4 import BeautifulSoup
soup = BeautifulSoup(demo,"html.parser")
for link in soup.find('tbody') :
 hotnumber=''
 if isinstance(link,bs4.element.Tag):
#  print(link('td'))
  lis=link('td')
  hotrank=lis[1]('a')[0].string#熱搜排名
  hotname=lis[1].find('span')#熱搜名稱
  if isinstance(hotname,bs4.element.Tag):
   hotnumber=hotname.string#熱搜指數(shù)
   pass
  mylist.append([lis[0].string,hotrank,hotnumber,lis[2].string])
f=open("d://hotsearch.txt","w+")
for line in mylist:
 f.write('%s %s %s %s\n'%(line[0],line[1],line[2],line[3]))

使用python怎么爬取微博的熱搜數(shù)據(jù)

知識(shí)點(diǎn)擴(kuò)展:利用python爬取微博熱搜并進(jìn)行數(shù)據(jù)分析

爬取微博熱搜

import schedule
import pandas as pd
from datetime import datetime
import requests
from bs4 import BeautifulSoup

url = "https://s.weibo.com/top/summary?cate=realtimehot&sudaref=s.weibo.com&display=0&retcode=6102"
get_info_dict = {}
count = 0

def main():
  global url, get_info_dict, count
  get_info_list = []
  print("正在爬取數(shù)據(jù)~~~")
  html = requests.get(url).text
  soup = BeautifulSoup(html, 'lxml')
  for tr in soup.find_all(name='tr', class_=''):
    get_info = get_info_dict.copy()
    get_info['title'] = tr.find(class_='td-02').find(name='a').text
    try:
      get_info['num'] = eval(tr.find(class_='td-02').find(name='span').text)
    except AttributeError:
      get_info['num'] = None
    get_info['time'] = datetime.now().strftime("%Y/%m/%d %H:%M")
    get_info_list.append(get_info)
  get_info_list = get_info_list[1:16]
  df = pd.DataFrame(get_info_list)
  if count == 0:
    df.to_csv('datas.csv', mode='a+', index=False, encoding='gbk')
    count += 1
  else:
    df.to_csv('datas.csv', mode='a+', index=False, header=False, encoding='gbk')

# 定時(shí)爬蟲(chóng)
schedule.every(1).minutes.do(main)

while True:
  schedule.run_pending()

pyecharts數(shù)據(jù)分析

import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Bar, Timeline, Grid
from pyecharts.globals import ThemeType, CurrentConfig

df = pd.read_csv('datas.csv', encoding='gbk')
print(df)
t = Timeline(init_opts=opts.InitOpts(theme=ThemeType.MACARONS)) # 定制主題
for i in range(int(df.shape[0]/15)):
  bar = (
    Bar()
      .add_xaxis(list(df['title'][i*15: i*15+15][::-1])) # x軸數(shù)據(jù)
      .add_yaxis('num', list(df['num'][i*15: i*15+15][::-1])) # y軸數(shù)據(jù)
      .reversal_axis() # 翻轉(zhuǎn)
      .set_global_opts( # 全局配置項(xiàng)
      title_opts=opts.TitleOpts( # 標(biāo)題配置項(xiàng)
        title=f"{list(df['time'])[i * 15]}",
        pos_right="5%", pos_bottom="15%",
        title_textstyle_opts=opts.TextStyleOpts(
          font_family='KaiTi', font_size=24, color='#FF1493'
        )
      ),
      xaxis_opts=opts.AxisOpts( # x軸配置項(xiàng)
        splitline_opts=opts.SplitLineOpts(is_show=True),
      ),
      yaxis_opts=opts.AxisOpts( # y軸配置項(xiàng)
        splitline_opts=opts.SplitLineOpts(is_show=True),
        axislabel_opts=opts.LabelOpts(color='#DC143C')
      )
    )
      .set_series_opts( # 系列配置項(xiàng)
      label_opts=opts.LabelOpts( # 標(biāo)簽配置
        position="right", color='#9400D3')
    )
  )
  grid = (
    Grid()
      .add(bar, grid_opts=opts.GridOpts(pos_left="24%"))
  )
  t.add(grid, "")
  t.add_schema(
    play_interval=1000, # 輪播速度
    is_timeline_show=False, # 是否顯示 timeline 組件
    is_auto_play=True, # 是否自動(dòng)播放
  )

t.render('時(shí)間輪播圖.html')

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。


新聞名稱:使用python怎么爬取微博的熱搜數(shù)據(jù)-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://fisionsoft.com.cn/article/cespcc.html