【问题标题】:Read/Write Data in Google Spreadsheet在 Google 电子表格中读取/写入数据
【发布时间】:2019-06-10 11:00:37
【问题描述】:

我没有在我的本地机器上使用 MS Office。所以我正在使用谷歌文档。

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

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

有人知道怎么做吗?

技术: Selenium Web 驱动程序 JAVA 测试NG Eclipse IDE

【问题讨论】:

  • 到目前为止你有什么尝试?
  • 您能否像示例一样打开公共电子表格并显示试图更改它的代码??
  • @AdiOhana:感谢您的意见。这是一个 Maven 项目,但我需要在 TestNg 中创建一个脚本。
  • @JalpeshPatel-QALead 我提到的 SO 帖子是使用 TestNG 和 Selenium

标签: selenium data-driven-tests


【解决方案1】:

我现在无法访问 Google 表格,但我猜它看起来像这样。

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://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

【讨论】:

  • 非常感谢您的努力和帮助。我已经阅读了您的评论并提供了链接,但它是一个 Python 代码。所以我没有在 selenium-java 中明确转换。
  • 哦,我明白了。对不起。我在搜索“Python”或“Selenium”时发现了这一点。我很快就读完了你的问题。我以为您正在寻找 Python/Selenium 解决方案,而不是 Java。我对Java一无所知。希望有人很快提出一个可行的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-04
相关资源
最近更新 更多