作者:难得有人待我好_212 | 来源:互联网 | 2023-09-06 20:45
selenium真是个好东西,最近无意间看到自己曾经的新浪微博,感觉之前发了很多垃圾信息,想要删掉。可惜微博太多,手删累人,于是就有了下面的代码。#!usrbinenvp
selenium真是个好东西,最近无意间看到自己曾经的新浪微博,感觉之前发了很多垃圾信息,想要删掉。
可惜微博太多,手删累人,于是就有了下面的代码。
#!/usr/bin/env python3.5
#coding:utf-8
from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
import time
ffbrowser = webdriver.Firefox()
wait = ui.WebDriverWait(ffbrowser,12)
def LoginWeibo(username,password):
try:
ffbrowser.get("http://weibo.com/login.php")
euser=ffbrowser.find_element_by_css_selector("div.input_wrap>input")
euser.send_keys(Keys.ENTER)
euser.send_keys(username)
epwd=ffbrowser.find_element_by_css_selector("[name='password']")
epwd.send_keys(Keys.ENTER)
epwd.send_keys(password)
# 为防止报:Firefox 中的不安全密码警示这个错误,因此点击下密码框附件的区域
eunsafe=ffbrowser.find_element_by_css_selector("[class='info_list auto_login clearfix']")
eunsafe.click()
#点击登录按钮
esubmit=ffbrowser.find_element_by_xpath("//a[@action-type='btn_submit']")
esubmit.click()
time.sleep(6)
eweibo=ffbrowser.find_element_by_css_selector("li>a[bpfilter='page_frame']")
eweibo.click()
except Exception as e:
print(e)
finally:
pass
def DeleteWeibo():
try:
time.sleep(6)
elists=ffbrowser.find_elements_by_css_selector(".W_ficon.ficon_arrow_down.S_ficon")
for e in elists[1:]:
e.click()
time.sleep(2)
ees=ffbrowser.find_elements_by_css_selector(".screen_box>.layer_menu_list>ul>li>a")
print(ees[0].text)
ees[0].click()
time.sleep(1)
eenter=ffbrowser.find_element_by_css_selector(".W_btn_a>span")
eenter.click()
time.sleep(2)
try:
time.sleep(1)
eclose=ffbrowser.find_element_by_css_selector(".W_ficon.ficon_close.S_ficon")
eclose.click()
time.sleep(2)
except:
pass
except Exception as e:
print(e)
finally:
pass
if __name__ == '__main__':
print("开始登录微博")
LoginWeibo("微博账号","微博密码")
print("登录成功")
i=1
while True:
print("开始第"+str(i)+"轮删除")
time.sleep(6)
DeleteWeibo()
i+=1
另外附上演示地址:
http://www.iqiyi.com/w_19ru2plqjt.html