Yash
Yash

Reputation: 45

CSV read specific row in python

I am a beginner in automation field.I have a CSV file with 50 rows each row contains urls.I'm trying to capture only specific rows.

csv file 1.www.google.com 2.www.facebook.com

import csv
from selenium import webdriver
chrome_path=(.......notepad++\chromedriver.exe')
driver=webdriver.Chrome(chrome_path)
driver.implicitly_wait(30)
driver.maximize_window()
with open('list.csv') as fb:
    reader=csv.reader(fb)
    rows=[r for r in reader]
driver.get(rows[1])
driver.quit()

error: selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'url' must be a string

Upvotes: 1

Views: 145

Answers (1)

Daniel McLaury
Daniel McLaury

Reputation: 4273

rows[1] is going to be a row, presumably corresponding to the second row of your CSV file.

I imagine your error message is coming from the call to driver.get, which is telling you it wants a string, not a row of strings. So I'd try grabbing whichever field in the row has the URL. I'm not sure how you're describing your CSV, but if it look like this:

1, google.com
2, facebook.com

then it should probably look something like this:

driver.get(rows[1][1])

Or, more readably,

number, url = rows[1]
driver.get(url)

Upvotes: 1

Related Questions