【python】實現文章同步csdn社群自動化

專注的阿熊發表於2022-06-30

# -*- 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部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2903720/,如需轉載,請註明出處,否則將追究法律責任。

相關文章