How Can I Iterate Through An Excel Sheet To Perform A Search On A Webpage Python Selenium
I want to iterate through a list of companies to search them one by one and save the href.
from selenium.webdriver import Firefox from selenium.webdriver.firefox.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import pandas as pd import pandas as pd from lxml import html import time import requests df=pd.read_excel('/Users/ap/companies.xlsx') browser = Firefox(options=opts) browser.get('https://webpage') search_form=browser.find_element_by_id('ctl00_ContentPlaceHolder1_frmEntityName') i=0 for i in df['company_name']: search_form.send_keys(i) search_form_buttom=browser.find_element_by_id('ctl00_ContentPlaceHolder1_btnSubmit').click() #wait a bit to make this element work.search_form.send_keys('BioHealth') time.sleep(15) i=i+1
I get the following error and I'm not able to sort it out, before even being able to scrape the hrefs.
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-68-e157420a273e> in <module>() 21 #wait a bit to make this element work.search_form.send_keys('BioHealth') 22 time.sleep(10) ---> 23 i=i+1 24 TypeError: coercing to Unicode: need string or buffer, int found
The for loop assignes the strings found in
df['company_name'] to it's variable
i. At the end of the loop you add
1 to this string, which is not allowed, as the python interpreter can not implicitly cast an int to a string.
I have the feeling, that you are trying to use the
i=i+1 as a loop counter variable, but that is not needed in a for-each-loop (i.e.
for i in foo). Just delete that
i=i+1. The loop will still run as expected.
However, if you really want to add a one to the string stored in
i, you have to write it like this:
Then the python interpreter will accept it.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module