我不在本地机器上使用MS office。所以我使用的是谷歌文档。
现在,我需要创建一个脚本,从Selenium中的google电子表格中获取数据。
我想使用selenium web驱动程序从Google电子表格中获取数据读/写。
有人知道怎么做吗?
技术: Selenium Web驱动程序JAVA TestNG Eclipse
发布于 2019-06-10 03:00:37
我现在无法访问谷歌页面,但我猜它会是这样的。
pip install gspread oauth2client
然后..。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Copy of Legislators 2017").sheet1
# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)
或者,获取一个列表:
sheet.get_all_values()
最后,您只需从一行、列或单元格中提取数据:
sheet.row_values(1)
sheet.col_values(1)
sheet.cell(1, 1).value
https://towardsdatascience.com/accessing-google-spreadsheet-data-using-python-90a5bc214fd2
https://stackoverflow.com/questions/56321292
复制相似问题