【不务正业系列】明星微博超话自动签到功能(selenium+python)

很想爬取各个明星超话的签到人数,做成可视化对比,看看谁更火来着,但是微博没有这样的接口,所以只能通过selenium+python实现超话自动签到来查看当前超话签到人数了。

#超话签到统计
#读取地址
adress = 'https://weibo.com/p/100808c915b5f06f94de5a702f6486acf308a5/super_index'
#读取微博账号密码
df = pd.read_excel(r'./微博账号密码.xlsx',sheet_name = 0,header = 0)
linumber = df.shape[0]
for i in range(0,linumber,1):
    username = str(df.iloc[i,0])
    password = df.iloc[i,1]
    print("此时登录的账号密码为",username,'----',password)
    wd = webdriver.Chrome('./chromedriver.exe')#你的chromedriver的地址
    wd.implicitly_wait(3) #每隔半秒钟再次执行可能抛出异常的代码,规避time.slepp()的万一情况
    wd.set_window_size(452, 790)
    wd.get("https://passport.weibo.cn/signin/login")
    elem = wd.find_element_by_xpath("//*[@id='loginName']");
    elem.send_keys(username)
    elem = wd.find_element_by_xpath("//*[@id='loginPassword']");
    elem.send_keys(password)
    elem = wd.find_element_by_xpath("//*[@id='loginAction']");
    elem.send_keys(Keys.ENTER) #等待3秒看登录的账号密码是否正确
    time.sleep(5)#输入验证码
#点击签到
print ('点击签到')
time.sleep(2)
wd.find_element_by_xpath('//*[@class="opt_box clearfix"]/div[3]').click()
time.sleep(2)
elem = wd.find_element_by_xpath('//*[@class="point clearfix"]/dd/div')
print(elem.text)
sign_num = elem.text #获取的超话签到数

运行结果如下,我们成功地获取了当前时间当前超话的签到人数:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yljwhat/article/details/107901308