import pyautogui
import time
import webbrowser
import random
import pyperclip
import os
rp = 1
for rp in range(150):
# 浏览器运行目录
chromePath = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
# 注册浏览器
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chromePath))
# 获取浏览器并打开指定地址
webbrowser.get('chrome').open('https://www.bilibili.com/v/life/daily/?spm_id_from=333.5.b_6c6966655f6461696c79.2#/',
new=1, autoraise=True)
# 睡眠5秒
# time.sleep(5)
# 关闭chrome浏览器
# os.system('taskkill /F /IM chrome.exe')
time.sleep(1)
pyautogui.size()
print(pyautogui.size())
# ————————————————打开指定网址——————
# time.sleep(3)效果不行
pyautogui.PAUSE = 1
# pyautogui.scroll(-800)
# pyautogui.click(x=287, y=231, clicks=1, interval=0.0, duration=0.0)
pyautogui.click(x=457, y=921, clicks=1, interval=0.0, duration=0.0)
# -----------打开第一个sp
# pyautogui.scroll(-300) # 向下滚动100
# _____________
while True:
# 跳过可能会发生的TypeError: cannot unpack non-iterable NoneType object错误
try:
# 搜索点赞按钮
img_find = pyautogui.locateOnScreen('0826.png')
left, top, width, height = img_find
except:
pass
if img_find:
# 点击按钮中心
time.sleep(2)
pyautogui.click(pyautogui.center((left, top, width, height)))
# 点击后停顿一下防止鼠标误点
# time.sleep(1)
t = random.randint(1, 9) # 模拟用户点击,随机时间操作
print(t)
time.sleep(t)
pyautogui.scroll(-600) # 向下滚动100
img_find2 = pyautogui.locateOnScreen('08262.png')
left, top, width, height = img_find2
# 点击按钮中心
time.sleep(2)
pyautogui.click(pyautogui.center((left, top, width, height)))
# pyautogui.typewrite('支持UP,期待回访', interval=0.25)
pyperclip.copy(random.choice(["支持UP,期待回访", "阿P的哲学支持UP,期待回访", "做UP不易,阿P的哲学来支持了"])) # 先复制
pyautogui.hotkey('ctrl', 'v') # 再粘贴
# 每次输入间隔0.25秒,输入Hello world!
# 点击后停顿一下防止鼠标误点
# time.sleep(1)
t = random.randint(1, 9) # 模拟用户点击,随机时间操作
print(t)
time.sleep(t)
img_find3 = pyautogui.locateOnScreen('08263.png')
left, top, width, height = img_find3
# 点击按钮中心
time.sleep(2)
pyautogui.click(pyautogui.center((left, top, width, height)))
# pyautogui.typewrite('支持UP,期待回访', interval=0.25)
# 每次输入间隔0.25秒,输入Hello world!
# 点击后停顿一下防止鼠标误点
# time.sleep(1)
t = random.randint(1, 9) # 模拟用户点击,随机时间操作
print(t)
time.sleep(t)
# pyautogui.PAUSE = 5
# 记录点赞次数
# print('成功点赞'+str(i)+'次')
print('成功点赞' + str(rp) + '次')
print('成功点赞')
# i+=1
else:
break
else:
break
如何实现python自动打开B站视频点赞并评论3?(随机选择不同评论)电脑分辨率1920*1080
最新推荐文章于 2024-05-06 10:47:00 发布