selenium實(shí)現(xiàn)模擬登錄 , 發(fā)帖
# 實(shí)現(xiàn)模擬登錄
def bitalk_log(username,password):
# 請(qǐng)求登錄頁(yè)面
try:
drive = webdriver.Chrome()
url = 'https://steemconnect.com/oauth2/authorize?client_id=duozhuan&redirect_uri=https%3A%2F%2Fwww.bitalk.cc%2Fcallback%2F&scope='
drive.get(url)
# 睡眠2秒
time.sleep(2)
# 找到continue按鈕點(diǎn)擊進(jìn)去
drive.find_element_by_xpath("http://button").click()
# 休眠0.5秒鐘后執(zhí)行填寫用戶名和密碼操作
time.sleep(0.5)
# 找到用戶名輸入用戶名
user = drive.find_element_by_id("username")
user.send_keys(username)
# 找到密碼輸入密碼
drive.find_element_by_id("password").send_keys(password)
# 點(diǎn)擊登錄按鈕實(shí)現(xiàn)登錄
drive.find_element_by_xpath("http://button").click()
# 登錄成功后跳轉(zhuǎn)首頁(yè),進(jìn)行加載,休眠10秒加載頁(yè)面
time.sleep(20)
# 點(diǎn)擊進(jìn)入發(fā)帖頁(yè)面
# drive.switch_to_default_content()
cookies_list = drive.get_cookies()
print(cookies_list)
return drive
except Exception as e:
print("出現(xiàn)問(wèn)題",e)
# 實(shí)現(xiàn)發(fā)帖
def fatie(drive,json):
global n
global nn
data = json
drive2 = drive
# 標(biāo)題
title = json['title']
# 主題
topics = json['topics']
# 內(nèi)容
body = json['content']
#圖片
files = json['files']
try:
drive.find_element_by_xpath("http://div[@class='right']//ul/li[1]/a").click()
time.sleep(5)
try:
# 標(biāo)題
drive.find_element_by_id('title').send_keys(title)
# 主題
for i in topics:
drive.find_element_by_id('topics').send_keys(i)
time.sleep(3)
drive.find_element_by_id('title').click()
# 上傳圖片
for i in files:
drive.find_element_by_id('editor-inputfile').send_keys(i)
time.sleep(4)
# 添加內(nèi)容
# drive.find_element_by_id('body').send_keys(body)
# 獎(jiǎng)勵(lì)
# 先定位到下拉框,點(diǎn)擊
# # 需要獎(jiǎng)勵(lì)的選項(xiàng)
# a = json['a']
# drive.find_element_by_xpath("http://div[@class='ant-select ant-select-enabled']").click()
# time.sleep(0.5)
# # 點(diǎn)擊下拉框下的選項(xiàng)
# if a == 1:
# drive.find_element_by_xpath("http://body/div[5]//ul/li[@unselectable='unselectable'][1]").click()
# time.sleep(0.5)
# elif a == 2:
# drive.find_element_by_xpath("http://body/div[5]//ul/li[@unselectable='unselectable'][2]").click()
# time.sleep(0.5)
# elif a == 3:
# drive.find_element_by_xpath("http://body/div[5]//ul/li[@unselectable='unselectable'][3]").click()
# time.sleep(0.5)
# 不喜歡這篇文章
b = json['b'] # 1表示不喜歡
if b == 1:
drive.find_element_by_xpath("http://input[@id='upvote']").click()
# 草稿進(jìn)行保存睡眠4秒
time.sleep(4)
# 發(fā)布
drive.find_element_by_xpath("http://button[@class='Action Action--big Action--primary']").click()
# 點(diǎn)擊發(fā)布跳轉(zhuǎn)加載頁(yè)面
time.sleep(10)
title1 = drive.find_element_by_xpath("http://div[@class='StoryFull']/h1[@class='StoryFull__title']").text
if title1 == title:
print('發(fā)布成功')
return False
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。