2016-12-01 3 views
0
import gspread 

gc = gspread.login("your login", "your password") 
wks = gc.open("document name").worksheet("sheet name") 

cellValue = wks.acell("A1").value 
print "Cell 'A1' has a value of %s" % cellValue 

たとえば、Googleシートドキュメントを表示するgspreadを使用できます。 Googleシートにアクセスして、PythonとSeleniumを使った自動テストで編集しようとする方法はありますか?自動テストPython/selenium gspread

+0

「アクセスGoogleのシートをとPythonとセレンを使用して自動テストでそれを編集しよう」明確にしてください – nithin

答えて

0

https://developers.google.com/people/quickstart/python

  • 上記のリンクにアクセスし、Googleアカウントに与えられた手順に従って、プロジェクトを作成します。

  • OAuthクライアントIDをダウンロードすると、client_secret.jsonが表示されます。

  • この例ではOAuthクライアントIDは使用されておらず、他のAPIを使用している間は必要になります。あなたはのOAuthクライアントID下回りますサービスアカウントキーをダウンロードする必要が上にaddtionで

  • 。 jsonとしてダウンロードしてください。

  • サービスアカウントキーへのパスは、次のコードの4行目に記載する必要があります。

コード:

import gspread 
from oauth2client.service_account import ServiceAccountCredentials 
#scope is necessary if we are accesing gdrive 
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive'] 
credentials = ServiceAccountCredentials.from_json_keyfile_name('/home/username/Downloads/MyProject.json', scope) 
gc = gspread.authorize(credentials) 

#to create a new gsheet 
sh = gc.create('Sheet_1') 

#to open existing gsheet 
sh = gc.open('LYKE') 

# to share to other users 
sh.share('[email protected]', perm_type='user', role='writer') 

#to create a worksheet in the gsheet 
worksheet = sh.add_worksheet(title='title', rows="500", cols="50") 

#Define a cell range and update cells 
cell_list = worksheet.range('A1:A10') 
for i,cell in enumerate(cell_list): 
    cell.value=i 
worksheet.update_cells(cell_list)