1.打开
2.新建一个文件
import selenium
import time
import requests
import socket
import win32api
import win32con
import xlrd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Ie()
time.sleep(1)
driver.maximize_window()
driver.implicitly_wait(5)
filename = r"D:\EnrollData.xls"
sheetname = "Logon"
data = xlrd.open_workbook(filename)
table = data.sheet_by_name(sheetname)
nrows = table.nrows
'''
for i in range(3):
print(i)
执行结果:0,1,2
下面这一行等同于这个循环
'''
for i in range(nrows):
row = table.row_values(i)
print(row[1])
if row[0]=="Y":
driver.get(row[1])
print(row[2])
driver.switch_to.frame("fraInterface")
driver.find_element_by_id("UserCode2").send_keys(row[2])
driver.find_element_by_id("PWD2").send_keys(row[3])
driver.find_element_by_name('submit2').send_keys(Keys.ENTER)
'''
# alt+s快捷键
# 按下alt
win32api.keybd_event(0x11, 0, 0, 0)
# 按下s
win32api.keybd_event(83, 0, 0, 0)
# 松开s
win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0)
# 松开alt
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
'''
hostname = socket.gethostname()
print(hostname)
IP = socket.gethostbyname(hostname)
print(IP)
aaa= driver.find_elements_by_class_name('currentImg')[0]
with open('spider_picture.jpg' ,'wb') as fb:
fb.write( requests.get(aaa.getAttribute("src")).data)
aaa.click()