python爬虫(一):爬取网页小说+AI智能读取文本

import requests
import re #正则表达式
#链接
url = 'https://www.ibswtan.com/70/70672/19808959.html'

res = requests.get(url)

a = res.encoding = 'utf-8'  #万国码

#提取数据
contents = re.findall('<div id="content">(.*?)</div>',res.text)
print(contents)

#自动创建文件 replace文本替换函数
with open('demo.txt','w') as f:
    for content in contents:
        f.write(content.replace('&nbsp;&nbsp;&nbsp;&nbsp;','').replace('<br/><br/>',''))

#初始化
import pyttsx3
# engine = pyttsx3.init()
# engine.say("你哈阿萨德")
# engine.runAndWait()

with open('demo.txt','r') as f:
    line = f.read()
    engine = pyttsx3.init()
    engine.say(line)
    engine.runAndWait()

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐