吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 7408|回复: 14
收起左侧

[Python 转载] 自动化脚本

  [复制链接]
reol_233 发表于 2019-5-6 19:23
在b站转发了500多条抽奖动态了,一次都没中。
500+条手动删太麻烦了,然后就写了个程序自动删除动态,分享一下。一起学习
[Python] 纯文本查看 复制代码
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[1]/div/div/div[1]/div[3]/p")))
            self.driver.find_element_by_xpath("//*[@id='page-dynamic']/div[1]/div/div/div[1]/div[2]/div").click()
            time.sleep(1)
            del_btn = self.driver.find_element_by_xpath("//*[@id='page-dynamic']/div[1]/div/div/div[1]/div[3]/p")
            del_btn.click()
            time.sleep(2)
            ok_btn = self.driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div/div[2]/div[2]/button[1]")
            ok_btn.click()
            print("已删除%d条" % (i + 1))

    def run(self):
        self._login()


if __name__ == '__main__':
    bili = Bili()
    bili.run()

免费评分

参与人数 4吾爱币 +6 热心值 +4 收起 理由
cwd903221990 + 1 + 1 热心回复!
低调的外围 + 1 + 1 热心回复!
zhangaiping1 + 1 + 1 学习了。~~~
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| reol_233 发表于 2019-5-6 20:19
pyxma214 发表于 2019-5-6 19:52
大佬有没有全自动抽奖的
虽然是凑个数 基本不中

下次尝试写一下
微风吹过。 发表于 2019-5-6 19:33
行云丶尘伤 发表于 2019-5-6 19:36
周峻弘 发表于 2019-5-6 19:40
selenium是个好东西,谁用谁知道 .
pyxma214 发表于 2019-5-6 19:52
大佬有没有全自动抽奖的
虽然是凑个数 基本不中
 楼主| reol_233 发表于 2019-5-6 20:18
如果有投稿的动态的话,就动不了了,刚刚删到一半卡住了
lymesh 发表于 2019-5-6 22:17
厉害了啊,感谢大佬
boliang 发表于 2019-11-12 03:29
大佬厉害= =
zhang923059 发表于 2019-12-6 11:02

在b站转发了500多条抽奖动态了,一次都没中  哈哈哈
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 23:39

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表