-1

當我從Excel中提取數據使用def功能在python硒,我我在單引號和雙引號中輸出(「」,「',[])。我不想在單引號或雙引號中輸出。當我從Excel中使用def函數提取數據在python中,我得到的單引號和雙引號(「」,'',[])輸出

另外,當我從使用硒的「Gmail應用程序」中的Excel工作表讀取數據時,它會讀取單引號和雙引號。

你們可以幫我解決這個問題嗎?

from selenium import webdriver 
from time import sleep 
from xlrd import open_workbook 
import xlrd 
import xlwt 



book=xlrd.open_workbook("E:\\Email.xlsx") 
print(book.nsheets) 
SheetName =book.sheet_by_name("gmail") 
rows=SheetName.nrows 
cols=SheetName.ncols 
def getcell(rows,cols): 

    table=list() 
    record=list() 

    for x in range(rows): 
     for y in range(cols): 
      record.append(SheetName.cell(x,y).value)  
      table.append(record) 
      record=[] 
      rows=rows+1 

    return table; 

v=getcell(1,1) 
print(str(v)) 

OUTPUT:

[ 'ABCDEFG']]

[ '[email protected]']

driver = webdriver.Chrome("C:\\Users\\home\\workspace\\geeko\\chromedriver.exe") 
driver.maximize_window() 
driver.get("https://www.gmail.com/") 
elem=driver.find_element_by_xpath("//*@id='identifierId']").send_keys(str(getcell(1, 1))) 
+0

你可以嘗試格式化你的代碼替換

elem=driver.find_element_by_xpath("//*@id='identifierId']").send_keys(str(getcell(1, 1))) 

?另外,您能否準確地說出您從電子表格中閱讀的內容以及您想要的期望值? – Tom

+0

我想輸出「[['abcdefg']] [['[email protected]']]沒有單引號或括號 – CPP

+0

我的意思是我得到輸出」[['abcdefg']] [['abc @ gmail.com']]與單引號和括號。我想要沒有單個,雙引號和括號的o/p – CPP

回答

0

確定添加此功能,您的代碼(注意它會將表連接在一個字符串中,但您可以使用您需要的任何分隔符對其進行修改

def strip_table(t): 
    out_str = "" 
    for item in t: 
     out_str += str(item[0]) 

    return out_str 

然後用

elem=driver.find_element_by_xpath("//*@id='identifierId']").send_keys(strip_table(getcell(1, 1))) 
+0

不工作。請幫助球員 – CPP

+0

CPP我剛剛更新了答案 – Dman

+0

nope沒有工作。通過添加上面的代碼,傳遞給gmail文本框的數據是null.Also也不會拋出任何錯誤消息。 – CPP

相關問題