python:在B站上实现自动互粉

2018-08-11  本文已影响0人  獨孤記憶
演示.jpg

需要:谷歌浏览器、chromedriver(对应浏览器版本的)

from selenium import webdriver
import time

def start_chrome():
    driver = webdriver.Chrome(executable_path='./chromedriver.exe')
    driver.start_client()
    return driver


def find_strangers():
    #css路径
    btn_sel='div.fans-action-btn.follow'
    #元素定位查找
    elems=driver.find_elements_by_css_selector(btn_sel)
    return elems

while True:
    url='https://www.bilibili.com/'
    follw_url = 'https://space.bilibili.com/40182889/#/fans/fans'
    driver =start_chrome()
    driver.get(url)
    #等待登录
    time.sleep(20)
    driver.get(follw_url)
    #等待页面加载
    time.sleep(6)
    strangers=find_strangers()
    for s in strangers:
        s.click()
        #每三秒点击一次
        time.sleep(3)

print('Done!')
time.sleep(3000)
上一篇下一篇

猜你喜欢

热点阅读