[python]代码库
# coding=utf-8
import xlrd
from selenium import webdriver
import time
acct=[]
xlsx = xlrd.open_workbook('shidai_pw.xlsx')
table = xlsx.sheet_by_name('Sheet1')
for x in range(2, 20):
if table.cell_value(x, 4) != "":
acct.append(table.cell_value(x, 2))
if table.cell_type(x,3)==2:
acct.append(str(int(table.cell_value(x, 3))))
else:
acct.append(table.cell_value(x, 3))
acct.append(table.cell_value(x, 4))
else:
break
opt = webdriver.ChromeOptions() # 创建浏览器
opt.set_headless() # 无窗口模式
driver = webdriver.Chrome(options=opt) # 创建浏览器对象
driver.implicitly_wait(15)
driver.get('http://www.zjsdxf.cn/dangjian/account/login.action') # 打开网页
# driver.maximize_window() #最大化窗口
time.sleep(2) # 加载等待
for x in range(0,int(len(acct)/3)):
driver.find_element_by_xpath('//*[@id="loginName"]').send_keys(acct[x*3])
driver.find_element_by_xpath('//*[@id="userPwd"]').send_keys(acct[x*3+1])
driver.find_element_by_xpath('//*[@id="loginSbmit"]').click() # 登录
driver.get('http://www.zjsdxf.cn/dangjian/study/listMyStudy.action')
time.sleep(2)
data = driver.find_element_by_xpath('//*[@id="myForm"]/div[2]/table/tbody/tr[2]').text
driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div[2]/a').click()
time.sleep(2)
# driver.save_screenshot('pic.png') # 截图
T = [acct[x*3+2], data]
print(T)
driver.close()