import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import json
print('使用说明:请先打开CSDN,登录你的账号,再用此款工具!')
'''打开csdn官网'''
web=webdriver.Chrome()
'''请输入搜索链接'''
sou=str(input("请输入搜搜链接:"))
c=web.get(f'{sou}')
'''保存cookies'''
get_cookie=web.get_cookies()
'''cookies转换json'''
get_json_cookue=json.dumps(get_cookie)
with open('cookie.json','w')as f:
f.write(get_json_cookue)
print("已经保存cookies")
time.sleep(2)
f.close()
'''删除获取的cookies'''
web.delete_all_cookies()
'''读取本地 cookies 模拟登录'''
with open('cookie.json','r',encoding='utf-8')as fs:
lists=json.loads(fs.read())
for i in lists:
web.add_cookie({
'domain':i['domain'],
'name':i['name'],
'value':i['value'],
'path':i['path']
})
ss=web.refresh()
time.sleep(2)
'''进行关注'''
web.find_element(by=By.XPATH,value='//*[@id="asideProfile"]/div[6]/div[2]').click()
time.sleep(2)
'''进行点赞'''
web.find_element(by=By.XPATH,value='//*[@id="spanCount"]').click()
time.sleep(2)
'''进行评论'''
web.find_element(by=By.XPATH,value='//*[@id="toolBarBox"]/div/div[2]/ul/li[5]').click()
time.sleep(2)
'''自动评论语句'''
web.find_element(by=By.XPATH,value='//*[@id="comment_content"]').send_keys('码文不易,大佬您太厉害了!')
time.sleep(2)
'''发送自动评论'''
web.find_element(by=By.XPATH,value='//*[@id="commentform"]/div/div[3]/div[3]/a/input').click()
time.sleep(2)