使用Python脚本从excel表中提取数据并输入网站
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39333004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use Python script to extract data from excel sheet and input into website
提问by Zotto
Hey I am python scripting novice, I was wondering if someone could help me understand how I could python, or any convenient scripting language, to cherry pick specific data values (just a few arbitrary columns on the excel sheet), and take the data and input into a web browser like chrome. Just a general idea of how this should function would be extremely helpful, and also if there is an API available that would be great to know.
嘿,我是 python 脚本新手,我想知道是否有人可以帮助我理解我如何使用 python 或任何方便的脚本语言来挑选特定的数据值(只是 Excel 表上的几个任意列),并获取数据和输入到 chrome 等网络浏览器。只是一个关于它应该如何运作的一般想法会非常有帮助,如果有一个可用的 API 会很高兴知道。
Any advice is appreciated. Thanks.
任何建议表示赞赏。谢谢。
回答by BSL-5
Okay. Lets get started.
好的。让我们开始吧。
Getting values out of an excel document
从 Excel 文档中获取值
This pageis a great place to start as far as reading excel values goes.
就阅读 excel 值而言,此页面是一个很好的起点。
Directly from the site:
直接从网站:
import pandas as pd
table = pd.read_excel('sales.xlsx',
sheetname = 'Month 1',
header = 0,
index_col = 0,
parse_cols = "A, C, G",
convert_float = True)
print(table)
Inputting values into browser
在浏览器中输入值
Inputting values into the browser can be done quite easily through Seleniumwhich is a python library for controlling browsers via code.
通过Selenium可以很容易地将值输入到浏览器中,Selenium是一个通过代码控制浏览器的 Python 库。
Also directly from the site:
也直接从网站:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
How to start your project
如何开始你的项目
Now that you have the building blocks, you can put them together.
现在您有了构建块,您可以将它们组合在一起。
Example steps:
示例步骤:
- Open file, open browser and other initialization stuff you need to do.
- Read values from excel document
- Send values to browser
- Repeat steps 2 & 3 forever
- 打开文件,打开浏览器和其他你需要做的初始化工作。
- 从excel文档中读取值
- 将值发送到浏览器
- 永远重复步骤 2 和 3