import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
'''创建浏览器对象'''
web=webdriver.Chrome()
'''打开csdn'''
web.get('http://csdn.net')
'''浏览器全屏'''
web.maximize_window()
'''弹出登录界面'''
web.find_element(by=By.XPATH,value='//*[@id="csdn-toolbar"]/div/div/div[3]/div/div[1]/a').click()
'''打开登录页面延迟5秒'''
time.sleep(10)
'''开始打开我的个人资料页面'''
web.find_element(by=By.XPATH,value='//*[@id="csdn-toolbar"]/div/div/div[3]/div/div[1]').click()
'''等待2秒'''
time.sleep(2)
'''点击查看我的粉丝'''
web.find_element(by=By.XPATH,value='//*[@id="userSkin"]/div[1]/div[2]/div[1]/div[1]/div[2]/div[2]/ul/li[4]/a').click()
time.sleep(3)
c=web.find_elements(by=By.XPATH,value='//*[@id="userSkin"]/div[2]/div/div[2]/div[1]/div[2]/div/div[2]')
ds=web.find_elements(by=By.CLASS_NAME,value='sub-btn')
'''循环关注前面人'''
for s in range(len(c)):
for i in ds:
'''点击关注'''
i.click()
time.sleep(1)
'''打开消息'''
web.find_element(by=By.XPATH,value='//*[@id="toolbar-remind"]').click()
time.sleep(3)
'''打开私信'''
web.find_element(by=By.XPATH,value='//*[@id="app"]/div/div[1]/ul/li[4]/a').click()
time.sleep(5)