1、预备chrome阅读器,对应版本的webdriver驱动
2、python装置selenium包
3、正在chrome中登录快手剖析发弹幕的进程
4、代码完成
5、运转
1、装置google阅读器下载驱动
google官网
(google拜访助手插件:链接:https://pan.百度.com/s/1XFazQydGjFyy-UZKTwqjgQ 提取码:30kz )
下载上去的是一个叫google拜访助手_v2.3.0.crx的扩大包
装置办法:
关上chrome阅读器,更多对象->扩大顺序->将该文件迁延到这里便可->要设置两个网址中的一个作为首页能力失常应用chrome阅读器。
装置与阅读器版本婚配的webdriver
1.关上google阅读器, 正在地点栏输出 chrome://version/ 查看版本信息
相似以下后果:
Google Chrome 79.0.3945.117 (正式版本) (64 位)
修订版本 04f0a055010adab4484f7497fbfdbf312c307f1d-refs/branch-heads/3945@{#1019}
操作零碎 Windows 10 OS (Build 10240.16384)
2.抉择合适版本的驱动下载,
下载地点:http://chromedriver.storage.谷歌apis.com/index.html
3.将chromedriver.exe 放正在Python环境目次下
如:D:\server\Python\Python37\chromedriver.exe
2、python装置selenium包
饬令行:pip install selenium
编译器pycharm:setting->Project Interpreter增加selenium便可
3、正在chrome中登录快手剖析发弹幕的进程
正在直播间这里输出内容,而后点击发送便可,以是代码要选中这个输出框,写入内容操作,并可以抉择发送这个按钮,而后点击操作。
4、代码完成
from selenium import webdriver
import time
# 导入类库
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\lxs\AppData\Local\Google\Chrome\User Data")
driver=webdriver.Chrome(options=options)
driver.get('https://live.kuaishou.com/u/......?csr=true')#关上一个页面
time.sleep(2) #缓两秒是让网页能到加载齐全
for i in range(0,10): #轮回10次,输出10次六六六
#经过chrome的css抉择器
input = driver.find_element_by_css_selector('#app > div.live-detail > div.liveroom-sidebar.light > div.chat > div.chat-actions > div.chat-input > div > textarea')
input.send_keys('六六六') #向元素输出3个六
submit = driver.find_element_by_css_selector('#app > div.live-detail > div.liveroom-sidebar.light > div.chat > div.chat-actions > div.chat-input > div > button')
submit.click() #点击操作
除了了以上正文外,还应留意css抉择器的应用:
按F12,抉择左上角的选项,就能正在页面中间接选中需求的元素了,以下操作:右键copy->selector(由于代码就是用这类模式抉择的)
5、运转代码
运转后果:
顺序本人关上chrome,拜访这个在直播的直播间,这里的六就是顺序本人敲下来的。依据代码,统共轮回输出提交10次。
总结:
由于真正模仿登岸临时不写进去,以是只能经过这类办法来完成,速率也慢。真正做到模仿登岸就会快不少倍,这类形式实用于无奈完成模仿登岸的状况。
以上就是装置chrome并经过selenium完成快手主动弹幕的具体内容,更多请存眷资源魔其它相干文章!
标签: python教程 python编程 python使用问题 selenium 弹幕
抱歉,评论功能暂时关闭!