西瓜直播弹幕阅读器 python
生活随笔
收集整理的這篇文章主要介紹了
西瓜直播弹幕阅读器 python
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
西瓜直播彈幕閱讀器 python
現在已經公布源代碼
https://github.com/shuishen49/xiguadanmu
?
原理如下,輸入房間號,打開西瓜直播網頁,爬取彈幕。
當然還有比這個更加聰明的辦法,但是我沒有實現。
爬取彈幕后,會自動朗讀彈幕內容。
適合沒有人氣的主播使用。
?
下載地址
https://github.com/shuishen49/xiguadanmu/releases/
備用百度網盤地址
鏈接: https://pan.baidu.com/s/1tqlRhS-fxjW0SEAg7UhfEw
提取碼: yc4i
?
還有一個cookies.txt文件自己隨便搞一下就行了。
from selenium import webdriver import json import time import win32com.client # import win32com # import key_Controller # from playsound import playsound # import tracebackold_list=[]__danmu_num=1def speak_text(text):#定義一個speak_text方法,并創建形參text,用于作為接下來讀取的文字speak = win32com.client.Dispatch("SAPI.SpVoice")#創建發聲對象speak.Speak(text)#使用發生對象讀取文字#填寫webdriver的保存目錄 room_id = input("請輸入房間號:") driver = webdriver.Chrome() #記得寫完整的url 包括http和https # driver.get('https://live.ixigua.com/1351108/') driver.get('https://live.ixigua.com/%s'%(room_id)) info_string="本軟件由西瓜視頻up主小鑫學渣開發,想獲取更多高級功能請聯系我。" print("西瓜視頻____小鑫學渣") speak_text(info_string) #首先清除由于瀏覽器打開已有的cookies driver.delete_all_cookies()with open('cookies.txt','r') as cookief:#使用json讀取cookies 注意讀取的是文件 所以用load而不是loadscookieslist = json.load(cookief)# 方法1 將expiry類型變為intfor cookie in cookieslist:#并不是所有cookie都含有expiry 所以要用dict的get方法來獲取if isinstance(cookie.get('expiry'), float):cookie['expiry'] = int(cookie['expiry'])driver.add_cookie(cookie)def langdu_danmu(danmu):#for循環提取html字典中嵌套的子字典data中嵌套的子字典room的內容賦值給text變量#這個html字典來自于get_danmu方法傳遞danmu=danmu.split(":",1)# print(len(str1))# yidu = Falseif len(danmu) > 1 :danmu_name=danmu[0][-6:]# danmu_name=danmu_name[-6:]danmu_content=danmu[1]# print(danmu_content)danmu_string=danmu_name + "說:" + danmu_contentprint(danmu_string)speak_text(danmu_string)else :danmu_string="歡迎"+danmu[0]print(danmu_string)speak_text(danmu_string)while True:a=driver.find_elements_by_class_name("chatroom__msg")try:langdu_danmu(a[__danmu_num].text)__danmu_num +=1except Exception as e:time.sleep(3)?
總結
以上是生活随笔為你收集整理的西瓜直播弹幕阅读器 python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为手机连按3次Android版本,向日
- 下一篇: C语言的指针移动怎么理解