I'm intending to open urls located in the excel files one by one
df = pd.read_excel("file", sheet_name="Sheet1"):
for i in range(0, len(df)):
driver.get()
This is what I've searched so far. I'll be appreciated if you give more tips. cheers!
CodePudding user response:
Assuming that your spreadsheet has a column heading (e.g., URL) on 'Sheet1' then:
import pandas
import requests
df = pandas.read_excel('file.xlsm', sheet_name='Sheet1')
for url in df['URL']:
requests.get(url)
# process the response here
CodePudding user response:
I would do something like this:
import os
import time
import pandas as pd
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install()
options = webdriver.ChromeOptions()
driver_path = r'D:\\Automation\\chromedriver.exe'
driver = webdriver.Chrome(options = options, executable_path=driver_path)
driver.maximize_window()
cwd = os.getcwd()
df = pd.read_csv(cwd "/csvfile_1.csv")
for index, row in df.iterrows():
driver.get(row['URL'])
time.sleep(5)
and this is how my CSV looks like:
that time.sleep(5)
is for visualization purpose, you can remove that once you test this code.