日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

江门android培训,基于selenium模块的江门市干部培训网络学院自动选课脚本

發(fā)布時(shí)間:2023/12/14 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 江门android培训,基于selenium模块的江门市干部培训网络学院自动选课脚本 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

[Python] 純文本查看 復(fù)制代碼# -*- coding: utf-8 -*-

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

from selenium.common.exceptions import TimeoutException

from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0

import time

import re

import random

from time import sleep

driver = webdriver.Chrome(executable_path="chromedriver.exe")

def login(username,passwd):

nickName=driver.find_element_by_id('nickName')

sourcePassword=driver.find_element_by_id('sourcePassword')

login_btn=driver.find_element_by_id('login_btn')

nickName.send_keys(username)

sourcePassword.send_keys(passwd)

time.sleep(10)

login_btn.click()

time.sleep(random.uniform(2,5))

try:

driver.find_element_by_class_name("layui-layer-btn0").click()

except:

print('是否登錄成功,若沒成功登陸,請(qǐng)重新運(yùn)行')

def course_need_Add(course_need_add):

course_need_add.click()

time.sleep(random.uniform(2,3))

course_need_add = driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[1]/div[1]/div[5]/a') # 詳情頁(yè)的選課

course_need_add.click()

time.sleep(random.uniform(1,3))

driver.find_element_by_xpath('/html/body/div[6]/div[3]/a[1]').click()

time.sleep(random.uniform(1,3))

driver.find_element_by_xpath('/html/body/div[7]/div[3]/a').click()

driver.back()

return print('選課成功')

base_url = "https://gbpx.jiangmen.cn/"

username=input("請(qǐng)輸入賬號(hào):")

passwd= input("請(qǐng)輸入密碼:")

print('請(qǐng)?jiān)跒g覽器網(wǎng)頁(yè)登錄界面賬號(hào)密碼自動(dòng)填充后15秒內(nèi)輸入驗(yàn)證碼')

driver.get(base_url)

driver.implicitly_wait(10)

now_window = driver.current_window_handle

login(username,passwd)

driver.implicitly_wait(15)

driver.find_element_by_id('navLesson').click()#進(jìn)入課程中心

driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[3]/div/div[2]/div[2]/div/div/a[6]').click()#點(diǎn)擊尾頁(yè)

time.sleep(3)

pageTotal=driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[3]/div/div[2]/div[2]/div/div/a[6]').text#獲取總頁(yè)數(shù)

print ("總共有"+pageTotal+"頁(yè)課程")

pageTotal=int(pageTotal)

page_start=input("請(qǐng)輸入開始選課的頁(yè)數(shù)(純數(shù)字):")

page_end=input("請(qǐng)輸入開始選課的頁(yè)數(shù)(純數(shù)字,不得大于總頁(yè)數(shù)):")

for page in range(page_start,page_end):

number = driver.find_element_by_xpath('//*[@class="layui-input"]')

number.clear()

number.send_keys(page)

driver.find_element_by_xpath('//*[@class="layui-laypage-btn"]').click()

driver.implicitly_wait(10)

print ("第"+str(page)+"頁(yè)")

for i in range(1,11):#對(duì)單個(gè)列表內(nèi)單個(gè)課程信息進(jìn)行判斷是否需要繼續(xù)學(xué)習(xí)。

xpath='/html/body/div[3]/div[2]/div[3]/div/div[2]/table/tbody/tr[{}]/td[5]/a'

couse_name='/html/body/div[3]/div[2]/div[3]/div/div[2]/table/tbody/tr[{}]/td[1]/a'

couse_name=couse_name.format(i)

xpath=xpath.format(i)

print(xpath)

time.sleep(random.uniform(1,3))

course_need_add = driver.find_element_by_xpath(xpath)

couse_name = driver.find_element_by_xpath(couse_name).text

print(course_need_add.text,couse_name)

if course_need_add.text == '已選':

i = i + 1

else:

course_need_Add(course_need_add)

time.sleep(random.uniform(1,3))

number = driver.find_element_by_xpath('//*[@class="layui-input"]')

number.clear()

number.send_keys(page)

driver.find_element_by_xpath('//*[@class="layui-laypage-btn"]').click()

time.sleep(5)

print("第" + str(page) + "頁(yè)")

總結(jié)

以上是生活随笔為你收集整理的江门android培训,基于selenium模块的江门市干部培训网络学院自动选课脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。