清空csdn回收站

1.想整理以前的一些东西,发现都比较杂乱,所以直接删除,想着可以直接全部选择一键删除,结果一个好家伙直接让我一条一条点,这能忍,直接给他安排自动化删除。

2.需要安装python依赖: selenium,lxml,time

pip install selenium
pip install lxml
pip install time

3.浏览器驱动:这里使用的谷歌浏览器驱动
注意匹配谷歌浏览器版本即可

4.详细代码

from selenium import webdriver
from lxml import etree
from time import sleep
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


if __name__ == '__main__':
    # 创建浏览器
    s = Service(executable_path='./chromedriver.exe')
    option = webdriver.ChromeOptions()
    # 启动时自动全屏
    option.add_argument('-kiosk')
    bro = webdriver.Chrome(chrome_options=option,service=s)
    with open('./stealth.min.js') as f:
        js = f.read()
        bro.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
            "source": js})
    # 打开网页
    url = 'https://mp.csdn.net/mp_blog/manage/article?spm=3001.5298'
    bro.get(url)
    sleep(2)
    # 切换扫码方式
    element= bro.find_element(By.CLASS_NAME, "login-third-app")
    # 点击
    element.click()
    # 扫码登录,暂停30秒
    sleep(15)
    # 重新打开
    bro.get(url)
    sleep(2)
    # page_text = bro.page_source
    # print(page_text)
    # 定位回收站
    reb= bro.find_element(By.XPATH, '//ul[@id="pills-tab"]/li[6]/span')
    # 获取回收站条数
    page_text = bro.page_source
    tree = etree.HTML(page_text)
    text = str(tree.xpath('//ul[@id="pills-tab"]/li[6]/span/text()')[0])
    print(type(text))
    print(text)
    # 回收站(215)
    value = int(text[text.find('(')+1:text.find(')')])
    reb.click()
    sleep(1)
    # 点击强烈推荐 //*[contains(text(),"搜索")]
    strong = bro.find_element(By.XPATH, '//*[contains(text(),"强烈推荐")]')
    strong.click()
    sleep(1)
    # 清空搜索框缓存内容
    bro.find_element(By.CLASS_NAME,'newnps-input').clear()
    sleep(1)
    # 在搜索输入框中输入
    bro.find_element(By.CLASS_NAME,'newnps-input').send_keys(u"111111")
    sleep(1)
    # 单击提交
    bro.find_element(By.CLASS_NAME,'newnps-btn').click()
    sleep(1)
    for index in range(value):
        # 鼠标悬停
        spotEle = bro.find_element(By.XPATH,'//div[@class="el-dropdown"]/span[@tabindex="0"]')
        ActionChains(bro).move_to_element(spotEle).perform()
        sleep(2)
        # 点击彻底删除
        bro.find_element(By.LINK_TEXT,'彻底删除').click()
        sleep(2)
        # 单击确定
        bro.find_element(By.CLASS_NAME, 'el-button--primary').click()
        sleep(2)
    bro.quit()

5.效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值