import pyautogui
import time
import webbrowser
import random
import pyperclip
import os
rp=1
for rp in range(2):
# 浏览器运行目录
chromePath = r"C:\Users\Administrator\AppData\Local\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)
#-----------打开第一个sp
pyautogui.scroll(-300) # 向下滚动100
#_____________
while True:
# 跳过可能会发生的TypeError: cannot unpack non-iterable NoneType object错误
try:
# 搜索点赞按钮
img_find = pyautogui.locateOnScreen('0209.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)
img_find2 = pyautogui.locateOnScreen('0210.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('支持UP,期待回访') # 先复制
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('02102.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站视频点赞并评论2?(解决不支持中文的问题)电脑分辨率1600*900
于 2022-02-10 11:56:10 首次发布