首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Google电子表格中读取/写入数据

在Google电子表格中读取/写入数据
EN

Stack Overflow用户
提问于 2019-05-27 07:10:08
回答 1查看 964关注 0票数 1

我不在本地机器上使用MS office。所以我使用的是谷歌文档。

现在,我需要创建一个脚本,从Selenium中的google电子表格中获取数据。

我想使用selenium web驱动程序从Google电子表格中获取数据读/写。

有人知道怎么做吗?

技术: Selenium Web驱动程序JAVA TestNG Eclipse

EN

回答 1

Stack Overflow用户

发布于 2019-06-10 03:00:37

我现在无法访问谷歌页面,但我猜它会是这样的。

代码语言:javascript
运行
复制
pip install gspread oauth2client

然后..。

代码语言:javascript
运行
复制
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)

或者,获取一个列表:

代码语言:javascript
运行
复制
sheet.get_all_values()

最后,您只需从一行、列或单元格中提取数据:

代码语言:javascript
运行
复制
sheet.row_values(1)

sheet.col_values(1)

sheet.cell(1, 1).value

https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html

https://towardsdatascience.com/accessing-google-spreadsheet-data-using-python-90a5bc214fd2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56321292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档