[Python] 自动读取网页新闻源码

2504 0
晓凤科技实名认证 2023-2-18 18:14:05 | 显示全部楼层 |阅读模式
import pyttsx3
import requests
from bs4 import BeautifulSoup
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
newVoiceRate = 130                       ## Reduce The Speech Rate
engine.setProperty('rate',newVoiceRate)
engine.setProperty('voice', voices[1].id)
def speak(audio):
  engine.say(audio)
  engine.runAndWait()
text = str(input("Paste article\n"))
res = requests.get(text)
soup = BeautifulSoup(res.text,'html.parser')

articles = []
for i in range(len(soup.select('.p'))):
    article = soup.select('.p')[i].getText().strip()
    articles.append(article)
text = " ".join(articles)
speak(text)
# engine.save_to_file(text, 'test.mp3') ## If you want to save the speech as a audio file
engine.runAndWait()
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

晓凤科技

初级红客

关注
  • 31
    主题
  • 11
    粉丝
  • 0
    关注
我是胡锦程,中国晓凤网络安全的创始人,会python等编程语言,懂得kali linux的使用,我时刻准备着,为中国网络安全事业作出贡献。

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行