Selenium學習一——批量操作句柄切換頁面

#創建工作簿
wbk = xlwt.Workbook(encoding='utf-8', style_compression=0)
#創建工作表
sheet = wbk.add_sheet('sheet 1', cell_overwrite_ok=True)
#表頭(table_top_list包含表頭每一列的值)
table_top_list = driver.find_element_by_xpath("//form[@name='studentForm']/div[3]/fieldset/table/thead/tr").find_elements_by_tag_name('td')
#寫入表頭到sheet 1中,第0行第c列
for c,top in enumerate(table_top_list):
    sheet.write(0, c, top.text)

# 表的內容
#將表的每一行存在table_tr_list中
table_tr_list = driver.find_element_by_xpath("//form[@name='studentForm']/div[3]/fieldset/table/tbody").find_elements_by_tag_name('tr')
for r,tr in enumerate(table_tr_list,1):
    #將表的每一行的每一列內容存在table_td_list中
    table_td_list = tr.find_elements_by_tag_name('td')
    #寫入表的內容到sheet 1中,第r行第c列
    for c,td in enumerate(table_td_list):
        sheet.write(r, c, td.text)
#保存表格到已有的 excel
wbk.save(r'C:\xxx\test.xls')


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章