【问题标题】:how to use Python script (selenium) to extract data from excel sheet and input into website如何使用 Python 脚本(selenium)从 excel 表中提取数据并输入到网站
【发布时间】:2020-06-05 01:47:43
【问题描述】:

我想知道如何从 Excel 电子表格中获取行数据并使用 selenium 将其输入到 cms 上的文本框中。我对如何将 1 行数据输入 1 个文本框以及将下一行数据输入下一个文本框感到困惑。

如果有人愿意提供帮助,那就太棒了。

谢谢你

【问题讨论】:

  • 你能添加你使用的实际代码吗?

标签: python excel pandas selenium automation


【解决方案1】:

您可以使用 pandas 从 selenium 中的 Keys 类中读取 excel 文件和 Keys。

这有一个函数列表,您可以传递它们以与浏览器交互,它们的 unicode(?可能是错误的)等价的。

class Keys(object):
    """
    Set of special keys codes.
    """

    NULL = '\ue000'
    CANCEL = '\ue001'  # ^break
    HELP = '\ue002'
    BACKSPACE = '\ue003'

import pandas as pd
from selenium.webdriver.common.keys import Keys
from selenium import webdriver



df = pd.read_excel(your_excel_file)


driver = webdriver.Chrome(your_driver)

### do stuff


data = df[your_data_col][0] # grabbing one value, you'll probably need to iterate using a loop.


driver.find_element_by_xpath(your_xpath).send_keys(data)
# do more stuff.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    相关资源
    最近更新 更多