python +selenium 循环在网站后台批量删除内容
网站含有某个词内容比较多,大约有30万条
程序是迅睿CMS
一次性删除的话,mysql就卡死了
于是就用python+selenium 循环在网站后台批量删除
每页500条,删除500次,这样就可以解放双手了
代码如下
from selenium import webdriver import time, os, shutil driver = webdriver.Chrome() driver.get("http://www.test.com/admin.php") time.sleep(2) username = driver.find_element_by_xpath('//input[@placeholder="账号"]') password = driver.find_element_by_xpath('//input[@placeholder="密码"]') presslogin = driver.find_element_by_xpath('//button[@type="submit"]') username.send_keys("admin") # 用户名 password.send_keys("admin") # 密码 presslogin.click() time.sleep(2) driver.get("http://www.test.com/admin.php?s=news&c=home&m=index") time.sleep(2) driver.find_element_by_xpath('//input[@name="keyword"]').send_keys("关键词") driver.find_element_by_xpath('//button[@type="submit"]').click() n = 1 while n < 501: checkall = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div/form/div[1]/table/thead/tr/th[1]/label/input') driver.execute_script("arguments[0].click();", checkall) driver.find_element_by_xpath('//button[@onclick="dr_module_delete()"]').click() time.sleep(5) driver.find_element_by_xpath('//*[@id="layui-layer1"]/div[3]/a').click() time.sleep(8) n = n +1 else: print("删除完毕")