ITPub博客

首页 > IT职业 > IT生活 > 【python】实现文章同步csdn社区自动化

【python】实现文章同步csdn社区自动化

IT生活 作者:专注的阿熊 时间:2022-06-30 17:11:18 0 删除 编辑

# -*- coding: utf-8-*-

import uiautomation as auto

import time

import subprocess

# subprocess.Popen('C:\Program Files\Google\Chrome\Application\chrome.exe')

time.sleep(2)

start_time = time.time()

print(' 开始时间: {}'.format(start_time))

auto.SetGlobalSearchTimeout(3)

content =外汇跟单gendan5.com auto.DocumentControl(Name=" 内容管理 -CSDN 创作中心 ", Classname="Chrome_RenderWidgetHostHWND")

# 点击同步至社区

tongbu = content.EditControl(Name=" 同步至社区 ")

if tongbu.Exists():

     tongbu.Click()

last_group = content.GetLastChildControl()

non_name_list = last_group.ListControl()

specific_list = non_name_list.GetChildren()

a = []

for i in specific_list:

     a.append(i.GetChildren()[0].Name)

print(a)

print(' 社区数 :', len(a))

yes = content.TextControl(Name=' 确认 ')

tongbu.Click()

s = 0

for i in a:

     # 先点一次同步,跳出框

     if tongbu.Exists():

         tongbu.Click()

     specific_community = content.TextControl(Name='{}'.format(i))

     # print(specific_community.Name)

     if s == 0:

         if not specific_community.Exists():

             s += 2

         else:

             specific_community.Click()

             if not yes.Exists():

                 s += 2

     if s > 0:

         content.GetLastChildControl().GetFirstChildControl().MoveCursorToMyCenter()

         auto.WheelDown(wheelTimes=s, waitTime=0.01)

         # 如果社区没显示出来,则滚动

         if not specific_community.Exists():

             # 鼠标放置中心

             content.GetLastChildControl().GetFirstChildControl().MoveCursorToMyCenter()

             # print(" 滚动 ")

             auto.WheelDown(waitTime=0.01)

             s += 2

             time.sleep(0.5)

             specific_community.Click(5, 5)

         # 有社区,但是只显示一点

         else:

             specific_community.Click(5, 5)

             if not yes.Exists():

content.GetLastChildControl().GetFirstChildControl().MoveCursorToMyCenter()

                 auto.WheelDown(waitTime=0.01)

                 s += 2

                 time.sleep(0.5)

                 specific_community.Click(5, 5)

                 yes = content.TextControl(Name=' 确认 ')

                 if yes.Exists():

                     yes.Click()

                     print(a.index(i) + 1, i, ' 已同步 ')

             else:

                 yes = content.TextControl(Name=' 确认 ')

                 if yes.Exists():

                     yes.Click()

                     print(a.index(i) + 1, i, ' 已同步 ')

     specific_community.Click(5, 5)

     yes = content.TextControl(Name=' 确认 ')

     if yes.Exists():

         yes.Click()

         print(specific_community.Name)

         print(a.index(i)+1, i, ' 已同步 ')

end_time = time.time()

sum_time = end_time - start_time

print(""" 运行时间: {}s""".format(sum_time))

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946337/viewspace-2903720/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-23

  • 博文量
    410
  • 访问量
    276778