Selenium 在谷歌电子表格中读/写数据
我没有在本地机器上使用MS office。所以我用的是谷歌文档 现在我需要创建一个脚本,用Selenium从google电子表格中获取数据 我想使用SeleniumWeb驱动程序从Google电子表格中获取数据[读/写] 有人知道怎么做吗 技术: Selenium Web驱动程序 JAVA TestNGSelenium 在谷歌电子表格中读/写数据,selenium,data-driven-tests,Selenium,Data Driven Tests,我没有在本地机器上使用MS office。所以我用的是谷歌文档 现在我需要创建一个脚本,用Selenium从google电子表格中获取数据 我想使用SeleniumWeb驱动程序从Google电子表格中获取数据[读/写] 有人知道怎么做吗 技术: Selenium Web驱动程序 JAVA TestNG EclipseIDE我现在没有访问Google工作表的权限,但我猜它看起来像这样 pip install gspread oauth2client 然后 import gspread from
EclipseIDE我现在没有访问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
我现在无法访问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
到目前为止您尝试了什么?您能否打开公共电子表格作为示例,并显示试图更改它的代码???@AdiOhana:谢谢您的输入。这是一个Maven项目,但我需要在TestNg中创建一个脚本。@JalpeshPatel QALead我提到的帖子正在使用TestNg和Selenium。到目前为止,您尝试了哪些方法?能否打开公共电子表格作为示例,并显示试图更改它的代码???@AdiOhana:谢谢您的输入。这是一个Maven项目,但我需要用TestNg创建一个脚本。@JalpeshPatel Qaso我提到的帖子正在使用TestNg和Selenium感谢您的努力和帮助。我已经阅读了你的评论并提供了链接,但这是一个Python代码。所以我没有在selenium-java中清楚地转换。哦,我明白了。很抱歉我在搜索“Python”或“Selenium”时发现了这一点。我很快就看完了你的问题。我以为您在寻找Python/Selenium解决方案,而不是Java。我对Java一无所知。希望不久有人能提出一个可行的解决方案。非常感谢你的努力和帮助。我已经阅读了你的评论并提供了链接,但这是一个Python代码。所以我没有在selenium-java中清楚地转换。哦,我明白了。很抱歉我在搜索“Python”或“Selenium”时发现了这一点。我很快就看完了你的问题。我以为您在寻找Python/Selenium解决方案,而不是Java。我对Java一无所知。希望不久有人能提出一个可行的解决方案。