简体   繁体   中英

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

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)

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