-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.py
51 lines (43 loc) · 1.33 KB
/
key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import xlrd
import time
from selenium import webdriver
def read_table(file = 'keyword.xls', sheet_index = 0):
data = xlrd.open_workbook(file)
table = data.sheets()[sheet_index]
nrows = table.nrows
list = []
for i in range(1, nrows):
row = table.row_values(i)
list.append(row)
return list
def openBrowser(firstParam, secondParam):
webdriver.get(url = firstParam + "/")
webdriver.find_element_by_id("kw").click()
webdriver.find_element_by_id("kw").clear()
webdriver.find_element_by_id("kw").send_keys(secondParam)
webdriver.find_element_by_id("su").click()
def goNextPage():
webdriver.find_element_by_link_text(u"下一页>").click()
def select(firstParam, secondParam):
list = webdriver.find_elements_by_xpath('//div/h3/a')
if firstParam:
list[int(firstParam)-1].click()
time.sleep(2)
if secondParam:
list[int(secondParam)-1].click()
def doTestJob(job):
jobType = job[0]
if jobType == 'open':
openBrowser(job[1], job[2])
elif jobType == 'nextPage':
goNextPage()
elif jobType == 'seletItem':
select(job[1], job[2])
if __name__ == '__main__':
webdriver = webdriver.Firefox()
list = read_table()
for k in range(len(list)):
job = list[k]
doTestJob(job)
time.sleep(5)
webdriver.quit()