目前不知道什么原因当标签页没有在前端显示时drissionpage驱动的midjourney生产器可能会陷入打不开且不刷新的困局从而停摆,我看了下可以用drissionpage操纵标签页定时前端显示,对于夜间自动可以打开这个程序。
切换标签页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 from DrissionPage import ChromiumPage, ChromiumOptionsimport timedo1 = ChromiumOptions().set_paths(local_port=9111 , user_data_path=r'C:/Users/A/AppData/Local/Google/Chrome/User Data' ) tab = ChromiumPage(addr_or_opts=do1) chuya_tab = tab.get_tab(url='Welcome to nginx!' ) kwf_tab = tab.get_tab(url='discord-d-com-s-mj3.aiwentu.net' ) switch_interval = 120 try : while True : chuya_tab.set .activate() print ("Switched to Tab chuya_tab" ) time.sleep(switch_interval) kwf_tab.set .activate() print ("Switched to Tab kwf_tab" ) time.sleep(switch_interval) except KeyboardInterrupt: print ("切换结束" )
初雅的midjourney生产器在upscale时滚动条会自动拉到最下面这导致要连续收割会十分麻烦要反复拉动滚动条,我一开始想研究里面的js机制,搞了半天放弃了,它这个可能涉及远程异步生成js,想用chrome的scroll插件滚动到顶部其实也不是个好选择因为往后并不是在顶部位置。后来我想到了用js监听延迟点击回到滚动条点击前的位置,然后又遇到了滚动条移动导致页面刷新会使js监听失效的问题用MutationObserver解决了,可以动态绑定监听。也就是说以后对于初雅的midjourney在收割时先开chrome console添加js动态监听,使得滚动条不会乱动。
防止chuya版midjourney生产器upscale时滚动条拉到底部在chromeconsole中运行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 function handleButtonClick (event ) { console .log ('按钮被点击了' ); var scrollContainer = document .querySelector ('.__scrollbar' ); const currentScrollTop = scrollContainer ? scrollContainer.scrollTop : window .scrollY ; console .log ('当前滚动位置是:' , currentScrollTop); if (scrollContainer) { console .log ('滚动容器滚动到按钮的位置' ); scrollContainer.scrollTo ({ top : currentScrollTop + 100 , behavior : 'smooth' }); } setTimeout (function ( ) { console .log ('延时 3 秒后,滚动回原来的位置' ); if (scrollContainer) { scrollContainer.scrollTo ({ top : currentScrollTop, behavior : 'smooth' }); } else { window .scrollTo ({ top : currentScrollTop, behavior : 'smooth' }); } }, 1500 ); } const observer = new MutationObserver (function (mutationsList, observer ) { mutationsList.forEach (function (mutation ) { if (mutation.type === 'childList' ) { const newButtons = document .querySelectorAll ('.__button' ); newButtons.forEach (function (button ) { if (!button.hasAttribute ('data-click-bound' )) { button.addEventListener ('click' , handleButtonClick); button.setAttribute ('data-click-bound' , 'true' ); } }); } }); }); observer.observe (document .body , { childList : true , subtree : true }); const allButtons = document .querySelectorAll ('.__button' );allButtons.forEach (function (button ) { if (!button.hasAttribute ('data-click-bound' )) { button.addEventListener ('click' , handleButtonClick); button.setAttribute ('data-click-bound' , 'true' ); } });
telegram自动搬运排版图文视频新闻,会遇到找不到div抛出异常并退出的问题,这个暂时还需要一些测试来验证。我估计是在翻译完之后进行页面滚动确保图片、视频加载的过程中发生了初始加载的div被删除了导致soup解析的先前版本的div在实际页面中找不到,那么就判断跳过它。重新soup获取message div涉及若在翻译期间发布了消息,那么这些消息肯定没有译文,我把翻译后的soup解析添加了message div包含class 为translated-text的子div条件,这样的话就排除那些没有译文的。
检测是否存在div避免telegram翻译程序找不到div退出 1 2 3 4 5 6 7 8 9 10 11 12 13 14 for message_div in top_limit_message_divs[:]: element = tab.ele(f"@id={message_div['id' ]} " ) if element is None : print ('scroll阶段发生找不到div异常!' ) top_limit_message_divs.remove(message_div) continue element.scroll.to_see() time.sleep(3 )
pinterest不知道什么时候改版了,那个收藏列表跑下面去了需要先scrolltobottom,页面中有两个列表符合xpath判断需要用[2]来表示。
pinterest下载收藏的pin图并删除 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 from DrissionPage import ChromiumPage, ChromiumOptionsfrom DrissionPage.common import Byfrom DrissionPage.common import Keysimport timeimport osimport sysdo1 = ChromiumOptions().set_paths(local_port=9111 , user_data_path=r'C:/Users/A/AppData/Local/Google/Chrome/User Data' ) tab = ChromiumPage(addr_or_opts=do1) tab.get('https://www.pinterest.com/tomyu2717/_pins/' ) time.sleep(3 ) while True : tab.scroll.to_bottom() time.sleep(3 ) containerxpath = (By.XPATH, f"(//div[contains(@class, 'vbI') and @role='list'])[2]" ) container_div = tab.ele(containerxpath) items = container_div.eles('.:Yl-' ) if not items: print ("没有找到要删除的元素,程序结束。" ) break for item in items: try : tab.actions.move_to(item) time.sleep(1 ) item.click() time.sleep(12 ) button1 = (By.XPATH, '//button[@aria-label="更多选项"]' ) more_button = tab.ele(button1) more_button.click() time.sleep(6 ) button4 = (By.XPATH, "//span[contains(@class, 'X8m') and text()='下载图片']" ) button_download = tab.ele(button4) button_download.click() time.sleep(2 ) tab.refresh() time.sleep(5 ) more_button = tab.ele(button1) more_button.click() time.sleep(6 ) button2 = (By.XPATH, "//span[contains(@class, 'X8m') and text()='编辑 Pin 图']" ) edit_button = tab.ele(button2) edit_button.click() time.sleep(6 ) button3 = (By.XPATH, "//div[contains(@class, 'RCK') and .//div[text()='删除']]" ) confirm_button1 = tab.ele(button3) confirm_button1.click() time.sleep(5 ) button5 = (By.XPATH, "//button[contains(@class, 'RCK') and .//div[text()='删除']]" ) confirm_button2 = tab.ele(button5) confirm_button2.click() time.sleep(5 ) pinmenu = (By.XPATH, "//div[contains(@class, 'DUt') and contains(@class, 'XiG')]//div[contains(@class, 'X8m') and text()='Pin 图']" ) pinmenu_button = tab.ele(pinmenu) pinmenu_button.click() time.sleep(5 ) tab.refresh() time.sleep(10 ) except Exception as e: continue print ("一次批量删除已完成。" ) time.sleep(1 ) print ("批量删除已完成。" )
清理了一下C盘用户文件夹appdata的各种缓存,通过下面的命令可以显示子文件夹的大小,我把网易、pip、unreal engine的缓存清理了一下,c盘之前只有30gb了清理后有70多gb。暂时就不进一步清理。在powershell中运行
展示目录下的所有文件夹的大小 1 2 3 4 5 6 Get-ChildItem "C:\path\to\your\folder" | ForEach-Object { "{0:N2} MB - {1}" -f ((Get-ChildItem $_ .FullName -Recurse | Measure-Object -Property Length -Sum ).Sum / 1 MB), $_ .FullName }
评论