安装chrome并通过selenium实现快手自动弹幕


当前第2页 返回上一页

四、代码实现

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(因为代码就是用这种模式选择的)QQ截图20200503130030.png

五、运行代码QQ截图20200503130712.png

运行结果:

程序自己打开chrome,访问这个正在直播的直播间,这里的六就是程序自己敲上去的。根据代码,总共循环输入提交10次。

总结:

因为真正模拟登陆暂时没有写出来,所以只能通过这种方法来实现,速度也慢。真正做到模拟登陆就会快很多倍,这种方式适用于无法实现模拟登陆的情况。

以上就是安装chrome并通过selenium实现快手自动弹幕的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python实现二维数组输出为图片_Python

Python操作mysql代码总结

Python爬虫买什么书?

Python语言能做什么工作

Python中记录循环次数的方法

Python代码写好了怎么运行

Python是免费的么

Python的五个特点

自学Python有什么网站

Python映射类型的相关介绍

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...