-- coding: utf-8 --
import time
import os
from selenium.webdriver import ActionChains
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
myusername = “XXX”#登录账号
mypassword = “XXX”#登录密码
driver = webdriver.Firefox() # 模拟浏览器打开网站
driver.get(“https://club.geely.com/login/registerorsginIn”)
try:
# 找到登录框,输入账号密码
driver.find_element_by_xpath("//*[@placeholder='输入手机号/昵称']").send_keys("账号")
driver.find_element_by_xpath("//*[@placeholder='请输入密码']").send_keys("密码")
time.sleep(60)
# 模拟点击登录
driver.find_element_by_xpath("//*[@class='button']").click()
time.sleep(1)
print("登陆完毕")
#进入个人中心
# driver.find_element_by_xpath('/html/body/div[4]/div[3]/div[1]/div[3]/div[1]/div[1]/div[1]/div[3]/ul/li[1]/span').click() # 定位语句去源码中找
driver.get("https://club.geely.com/personalCenter/personalProfile")
time.sleep(1)
# 模拟点击签到
#driver.find_element_by_xpath("//*[@id='qd_button']").click()
botton = 'document.getElementsByClassName("el-button el-button--primary")[0].click();'
driver.execute_script(botton)
# driver.find_element_by_xpath("/html/body/div[4]/div[7]/div[1]/div[3]/div[2]/div[1]/button/span").click()
time.sleep(1)
print("签到成功")
#每日任务
driver.get("https://club.geely.com/personalCenter/myMessionNew?type=2")
#立即申请
time.sleep(1)
driver.get("https://club.geely.com/bbs/home.php?mod=task&do=apply&id=21&itemtype=everyday")
#试试这个
# driver.find_element_by_css_selector("//a[text()='https://club.geely.com/bbs/home.php?mod=task&do=apply&id=21&itemtype=everyday']").send_keys(Keys.ENTER)
# 打开网址七嘴八舌
driver.get("https://club.geely.com/bbs/forum.php?mod=forumdisplay&fid=730")
# 下滑到页面最下面
time.sleep(1)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
#进入回复点赞页面
#ActionChains(driver).move_by_offset(50.1667, 20.05).click().perform() # 鼠标左键点击, 200为x坐标, 100为y坐标
driver.find_element_by_xpath('/html/body/div[11]/div[4]/div/div/div[4]/div/form/div/div[1]/div[12]/div[1]/div[1]/a').click() # 定位语句去源码中找
# 下滑到页面最下面
time.sleep(1)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
time.sleep(1)
print("滑到最下面")
#点赞
driver.find_element_by_css_selector("html.widthauto body#nv_forum.pg_viewthread div.wp.cl div#article-detail div#p_btn.mtw.mbm.hm.cl a#recommend_add span").click()
time.sleep(1)
print("点赞")
#收藏
driver.find_element_by_css_selector("html.widthauto body#nv_forum.pg_viewthread div.wp.cl div#article-detail div#p_btn.mtw.mbm.hm.cl a#k_favorite span").click()
time.sleep(1)
time.sleep(1)
#分享
driver.find_element_by_css_selector("html.widthauto body#nv_forum.pg_viewthread div.wp.cl div#article-detail div#p_btn.mtw.mbm.hm.cl a.sharep span").click()
time.sleep(1)
#微信二维码点击
driver.find_element_by_css_selector("html.widthauto body#nv_forum.pg_viewthread div.wp.cl div#article-detail div#p_btn.mtw.mbm.hm.cl div#shareShadow div#shareBlock div.share-body div.share-list div.shareContent img").click()
time.sleep(2)
print("打开二维码")
#关闭二维码
#driver.close()
# 打开网址七嘴八舌
driver.get("https://club.geely.com/bbs/forum.php?mod=forumdisplay&fid=730")
# 下滑到页面最下面
time.sleep(1)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
# 回复1
driver.get("https://club.geely.com/bbs/forum.php?mod=viewthread&tid=1375300&extra=page%3D1")
time.sleep(1)
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
driver.find_element_by_xpath("//*[@id='fastpostmessage']").send_keys("我想中个车模,祝自己好运 ")
driver.find_element_by_xpath("//*[@id='fastpostsubmit']").click()
time.sleep(10)
# 回复2
driver.get("https://club.geely.com/bbs/forum.php?mod=viewthread&tid=1372360&extra=page%3D1")
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
driver.find_element_by_xpath("//*[@id='fastpostmessage']").send_keys("我旅途就要都准备好 ")
time.sleep(10)
driver.find_element_by_xpath("//*[@id='fastpostsubmit']").click()
time.sleep(1)
# 回复3
driver.get("https://club.geely.com/bbs/forum.php?mod=viewthread&tid=1118857&extra=page%3D1")
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
driver.find_element_by_xpath("//*[@id='fastpostmessage']").send_keys("老版的车机表示,已经被抛弃")
time.sleep(10)
driver.find_element_by_xpath("//*[@id='fastpostsubmit']").click()
time.sleep(10)
# 发布帖子
driver.get("https://club.geely.com/bbs/forum.php?mod=post&action=newthread&fid=726")
Select(driver.find_element_by_id('firstSelect')).select_by_value('1')
Select(driver.find_element_by_id('forumSelect')).select_by_value('730')
driver.find_element_by_xpath("//*[@id='subject']").send_keys("今天路上真堵车")
#print(driver.page_source)
#print('-----------zhendu-----------------')
#文本框在document和iframe下面
#xpath = driver.find_element_by_xpath("//div[@class='area']/iframe")
#driver.switch_to_.frame(xpath) # 文本内容在iframe中
#element = driver.find_element_by_xpath("//*[@id='subject']")
#time.sleep(1)
#element.send_keys(Keys.TAB)
#element.send_keys("ddd")
#xpath = driver.find_element_by_xpath("//div[@class='area']/iframe")
#driver.switch_to_.frame('e_iframe') # 文本内容在iframe中
#driver.find_element('tag name','body').send_keys("今天路上真堵车")
#driver.switch_to_default_.content() # 发送按钮在iframe外,所以需要跳出
#富文本框输入内容
js = "document.querySelector('#e_iframe').contentDocument.querySelector('body').innerHTML='<h1>今天是真的真堵车呀。。</h1>'"
driver.execute_script(js)
time.sleep(3)
botton3 = 'document.getElementsByClassName("online-btn")[0].click();'
driver.execute_script(botton3)
time.sleep(2)
botton4 = 'document.getElementsByClassName("img-block")[0].click();'
driver.execute_script(botton4)
time.sleep(1)
botton5 = 'document.getElementsByClassName("online-chouse-btn")[0].click();'
driver.execute_script(botton5)
time.sleep(1)
#发表帖子
time.sleep(4)
driver.find_element_by_xpath("//*[@id='postsubmit']/span").click()
print("发表帖子成功")
time.sleep(3)
#返回个人空间正在执行任务
driver.get("https://club.geely.com/personalCenter/myMessionNew?type=2")
js = "window.open('https://club.geely.com/bbs/home.php?mod=task&item=doing&itemtype=everyday')"
driver.execute_script(js)
time.sleep(3)
#切换窗口
handles = driver.window_handles
driver.switch_to.window(handles[1])
time.sleep(3)
#领取奖励
driver.find_element_by_css_selector("html.widthauto body div#ct.ct2_a.wp.cl div.mn div.bm.bw0 div.ptm table tbody tr td.bbda p a.messionApply").click()
time.sleep(2)
except:
print(“签到失败”)
driver.quit # 退出去动