I want to fill webforms using selenium web driver in python language. thats not a tough task indeed but I am unable to find out how can fill the webform when the data must be taken from excel file.
I have tried selenium to fill webform that is possible and easy
rom selenium import webdriver
driver = webdriver.Chrome("C:\\chrome_driver\\chromedriver_win32\\chromedriver.exe")
driver.get("https://admin.typeform.com/signup")
driver.find_element_by_id("signup_owner_alias").send_keys("Bruce Wayne")
driver.find_element_by_id("signup_owner_email").send_keys("bruce.wayne#gmail.com")
driver.find_element_by_id("signup_terms").click()
driver.find_element_by_id("signup_owner_language").click()
You can use the pandas library to fetch the data from your excel sheet. If you don't have it installed, you install it with pip: pip install pandas.
Below is an example of how data is fetched from an excel sheet using pandas.
import pandas as pd
df = pd.read_excel('centuries.xls')
sheet_years = df['Year']
for year in sheet_years:
print(year)
Basically, we fetched the excel sheet (centuries.xls) using the read_excel() method. Then we saved one of the columns ('Years' column in this example), in a variable (sheet_years). You can do same with other columns.
Rows in the saved column are automatically saved as list items, so we can iterate over these items using our for loop. You can replace it with your own code, instead of just printing the items in the list.
If your excel file contains more than one sheet, you can use the sheet_name parameter of the read_excel() method.
After doing the job with pandas, you can then send the output to your selenium code to fill the forms.
More information here:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html
https://www.dataquest.io/blog/excel-and-pandas/
Related
I'm trying to convert an excel sheet into a doc object using spacy, I spent the last couple of days trying to go around it but it seems a bit challenging. I have opened the sheet in both openpyxl and pandas, I can read the excel sheet and output the content but I couldn't integrate spacy to create doc/token objects.
Is it possible to process excel sheets in spacy's pipeline?
Thank you!
Spacy has no support for excel.
You could use pandas to read either the csv(if csv format)
or excel file
like
import pandas as pd
df = pd.read_csv(file)
or
df = pd.read_excel(file)
respectively.
Select required text column and iterate over df 'column' values and pass them over to nlp() of spacy
I'm trying to write the time data into excel with python (I'm using Pandas). When I write time data to excel I have excel number format 'General':
Sample Screenshot
But I need to have the number format as 'Time' - which I have when I paste the data as values manually to the excel file.
Is it possible to do the same with python? If yes how can I do it?
I have tried to change the values into DateTime object but when I write the data it always deletes cells format in excel file
df['starttime'] = pd.to_datetime(df['starttime']).dt.strftime('%I:%M:%S %p')
Have you tried to use Pandas?
Writing Excel Files Using Pandas
We'll be storing the information we'd like to write to an Excel file
in a DataFrame. Using the built-in to_excel() function, we can extract
this information into an Excel file.*
Step 1: install pandas in your py env
pip install pandas
Step 2: let's import the Pandas module:
import pandas as pd
Step 3:
use the to_excel() function to write the contents to a file. The only argument is the file path:
df.to_excel('./states.xlsx')
I have a web page where I need to enter number of site one by one and fetch data for each of those sites. The site names are kept in an excel column. I am trying to automate this thing using python and selenium and stuck at this step.
I am absolute beginner and working on my first automation project and need help. I am able to login to web page using selenium and click on the tab that pops the window to enter site name.
A sample code with some explanation will be very useful.
1) First, you have to save your excel to csv, it is the easiest way to import data from excel to python,
2) Second, you have to import your column with sites names using csv library to a list, for example:
import csv
list = []
def read_csv(file_path):
with open(file_path) as f:
csv_content = csv.DictReader(f)
for row in csv_content:
global list
list.append(row['sitesNamesColumn'])
read_csv('pathToYourFile') # better to keep file in a project
3) Third, you have to type the site`s name to some input:
for site in list:
#click on the tab that pops the window to enter the site name
input.send_keys(site)
#fetch data
I am coming from java background and have minimal idea regarding python. I have to read an excel file and validate one of it's column values in the DB to verify that those rows exist in the DB or not.
I know the exact libraries and steps in java using which I can do this work.
But I am facing problems in choosing the ways to do this work in python.
till now I am able to identify some things which I can do.
Read excel file in python using python.
Use pyodbc to validate the values.
Can pandas help me to refine those steps. Rather doing things the hard way.
Yes pandas can help. But you phrase the question in a "please google this for me" way. Expect this question to be down-voted a lot.
I will give you the answer for the excel part. Surely you could have found this yourself with a little effort?
import pandas as pd
df = pd.read_excel('excel_file.xls')
Read the documentation.
Using xlrd module, one can retrieve information from a spreadsheet. For example, reading, writing or modifying the data can be done in Python. Also, a user might have to go through various sheets and retrieve data based on some criteria or modify some rows and columns and do a lot of work.
xlrd module is used to extract data from a spreadsheet.
# Reading an excel file using Python
import xlrd
# Give the location of the file
loc = ("path of file")
# To open Workbook
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
# For row 0 and column 0
sheet.cell_value(0, 0)
put open_workbook under try statement and use pyodbc.Error as exe in except to catch the error if there is any.
So i have this script that outputs a pandas dataframe which i can save to a notebook. These tables however arent professional looking and i was wondering if there was a way in pandas/excel writing modules that would allow me to add column headers to my columns , a legend, merge cells, add a title, etc.
This is what i get from python as a pandas dataframe:
with this script:
excel_df=pd.DataFrame(closeended_all_counts).T
excel_df.columns=all_columns
writer=pd.ExcelWriter('L:\OMIZ\March_2018.xlsx',engine='xlsxwriter')
excel_df.to_excel(writer,'Final Tables')
workbook = writer.book
worksheet = writer.sheets['Final Tables']
writer.save()
whereas i need this output:
any documentation or modules would be amazing!
Since you're looking for documentation, here you go:
https://xlsxwriter.readthedocs.io/example_tables.html?highlight=tables