Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert URLs imported from .csv to string – Python

I’m attempting to read URLs from a .csv file to begin a loop. My csv file only contains URLs.
While trying to read the URL from the csv file, i’m receiving this error: Message: invalid argument: 'url' must be a string

I’ve only included relevant code. Thank you in advance for any insight/help.

from csv import reader, writer
driver = webdriver.Chrome()

with open('work2.csv', 'r') as f:


   urls = thereader = reader(f)

 
   for url in urls:
      driver.get(url)
    

CSV

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you read from a csv file it will read each row in form of list so to get the url you just take the first one.

from csv import reader, writer
driver = webdriver.Chrome()

with open('work2.csv', 'r') as f:


   urls = thereader = reader(f)

 
   for url in urls:
      driver.get(url[0])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading