自动化脚本
在b站转发了500多条抽奖动态了,一次都没中。500+条手动删太麻烦了,然后就写了个程序自动删除动态,分享一下。一起学习
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
class Bili(object):
driver_path = r"D:\ProgramApp\chromedriver_win32\chromedriver.exe"
def __init__(self):
self.driver = webdriver.Chrome(executable_path=Bili.driver_path)
self.login_url = "https://passport.bilibili.com/login"
self.home_url = "https://www.bilibili.com/"
self.space_url = "https://space.bilibili.com"
def _login(self):
self.driver.get(self.login_url)
WebDriverWait(self.driver, timeout=1000).until(EC.url_to_be(self.home_url))
print("登陆成功")
self._to_space()
def _to_space(self):
self.driver.get(self.space_url)
space_url_id = self.driver.current_url
dynamic_url = space_url_id + '/dynamic'
for i in range(500):
self.driver.get(dynamic_url)
WebDriverWait(self.driver, timeout=30).until(EC.presence_of_all_elements_located((By.XPATH, "//*[@id='page-dynamic']/div/div/div/div/div/p")))
self.driver.find_element_by_xpath("//*[@id='page-dynamic']/div/div/div/div/div/div").click()
time.sleep(1)
del_btn = self.driver.find_element_by_xpath("//*[@id='page-dynamic']/div/div/div/div/div/p")
del_btn.click()
time.sleep(2)
ok_btn = self.driver.find_element_by_xpath("/html/body/div/div/div/div/div/div/button")
ok_btn.click()
print("已删除%d条" % (i + 1))
def run(self):
self._login()
if __name__ == '__main__':
bili = Bili()
bili.run() pyxma214 发表于 2019-5-6 19:52
大佬有没有全自动抽奖的
虽然是凑个数 基本不中
下次尝试写一下 大佬好厉害····· 咱也不知道 咱也不敢问 selenium是个好东西,谁用谁知道 . 大佬有没有全自动抽奖的
虽然是凑个数 基本不中
如果有投稿的动态的话,就动不了了,刚刚删到一半卡住了 厉害了啊,感谢大佬 大佬厉害= =
在b站转发了500多条抽奖动态了,一次都没中哈哈哈
页:
[1]
2