如何将从 .csv 导入的 URL 转换为字符串 - Python

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

我正在尝试从 .csv 文件中读取 URLs 以开始循环。我的 csv 文件只包含 URLs。 尝试从 csv 文件读取 URL 时,我收到此错误:Message: invalid argument: 'url' must be a string

我只包含了相关代码。预先感谢您的任何 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

当您从 csv 文件中读取时,它将以列表的形式读取每一行,因此要获得 url 您只需读取第一行。

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])