简体   繁体   中英

how to use Python script (selenium) to extract data from excel sheet and input into website

I was wondering how I would be able to get rows data from an excel spreadsheet and input it into text boxes on a cms using selenium. I was confused on how i would enter 1 row of data into 1 text box and the next row of data into the next text box.

if someone would be kind of enough to help, that would be amazing.

thank you

you can use pandas to read an excel file and Keys from the Keys class in selenium.

this has a list of functions you can pass to interact with the browser with their unicode(? might be wrong) equivilent.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM