嗶哩嗶哩彈幕處理 情感傾向分析

2021-10-17 20:27:29 字數 2911 閱讀 4503

將xml彈幕解析,並寫入csv檔案

**部分:

import xml.etree.elementtree as et

import csv

import time

tree = et.elementtree(

file

='test.xml'

)root = tree.getroot(

)# print(root.tag,root.text,root.attrib)

f =open

('嗶哩嗶哩xml彈幕輸出.csv'

,'w'

,encoding=

'utf-8'

,newline='')

csv_writer = csv.writer(f)

csv_writer.writerow(

["彈幕內容"

,"秒數"

,"彈幕模式"

,"字型大小"

,"字型顏色"

,"時間戳"

,"彈幕池"

,"傳送者id"

,"彈幕在彈幕資料庫中rowid"])

neirong = root.findall(

'd')

for i in neirong:

# print(type(i.attrib)) 字典型別

notcut = i.attrib[

'p']

cut = notcut.split(

",")

unix_timestamp =

int(cut[4]

) beijing_time = time.localtime(unix_timestamp)

beijing_time = time.strftime(

"%y-%m-%d %h:%m:%s"

,beijing_time)

print

(cut)

#列表型別

csv_writer.writerow(

[i.text,cut[0]

,cut[1]

,cut[2]

,cut[3]

,beijing_time,cut[5]

,cut[6]

,cut[7]

])# 第乙個引數是彈幕出現的時間 以秒數為單位。

# print(alone)

# 第二個引數是彈幕的模式1..3 滾動彈幕 4底端彈幕 5頂端彈幕 6.逆向彈幕 7精準定位 8高階彈幕

# 第三個引數是字型大小, 12非常小,16特小,18小,25中,36大,45很大,64特別大

# 第四個引數是字型的顏色 以html顏色的十位數為準

# 第五個引數是unix格式的時間戳。基準時間為 1970-1-1 08:00:00

# 第六個引數是彈幕池 0普通池 1字幕池 2特殊池 【目前特殊池為高階彈幕專用】

# 第七個引數是傳送者的id,用於「遮蔽此彈幕的傳送者」功能

# 第八個引數是彈幕在彈幕資料庫中rowid 用於「歷史彈幕」功能。

for i in neirong:

# print(i.tag,i.attrib,i.text)

print

(i.text)

csv_writer.writerow(

[i.text]

)f.close(

)

結果如下:

**如下:

import xml.etree.elementtree as et

import csv

from aip import aipnlp

import time

tree = et.elementtree(

file

='test.xml'

)root = tree.getroot(

)f =

open

('xml彈幕情感分析.csv'

,'w'

,encoding=

'utf-8'

,newline='')

api_key =

secret_key =

csv_writer = csv.writer(f)

# csv_writer.writerow(["彈幕內容","秒數","彈幕模式","字型大小","字型顏色","時間戳","彈幕池","傳送者id","彈幕在彈幕資料庫中rowid"])

neirong = root.findall(

'd')

for i in neirong:

classify = client.sentimentclassify(i.text)

; time.sleep(

0.3)

if classify[

"items"][

0]['sentiment']==

0:sentiment =

"消極"

elif classify[

"items"][

0]['sentiment']==

1:sentiment =

"中性"

else

: sentiment =

"積極"

print

(classify[

"text"

], sentiment)

csv_writer.writerow(

[i.text,sentiment]

)f.close(

)

執行結果:

嗶哩嗶哩 嗶哩嗶哩,危!!!

以前的時候,唧唧down很好用,不管是網頁還是客戶端,都能滿足要求。最近在用的時候,網頁端老是出問題 用客戶端吧,也感覺沒有以前順手了。兩者都是便攜版,解壓後直接執行主程式,無需安裝。不過唧唧有安裝版,多乙個選擇吧,問題不大,因為我更喜歡便攜版。檔案大小350mb,相比1080p畫質,位元速率提公升...

爬蟲 之 抓取嗶哩嗶哩彈幕

第三步 擼 coding utf 8 from parsel import selector import requests def get url headers body requests.get url,headers headers content 我擦,居然出現亂碼 xbody selec...

20190910嗶哩嗶哩

給定乙個陣列,這些數連在一起可以組成乙個大數,求能組成最大數。如 3,30,34,5,9 能組成的最大數為 9534330。由於組成的數可能非常大,用字串返回。include include include include include include include include includ...