简体   繁体   中英

Python > Selenium + CSV: Webdriver to read, visit all links in .csv file

This question is about using a webdriver ( "ChromeDriver", Selenium ) to:

1) Look-up a .csv file; and
2) Visit all links in the file, one at a time, until the list is over.

I've put together a simple code:

from selenium import webdriver
import time
import csv

driver = webdriver.Chrome()

Assume link.csv contains the following sites:
• www.google.com
• www.wikipedia.org
• www.yahoo.com

f = open('link.csv', 'r', encoding='utf-8')
reader = csv.reader(f)

for line in reader:
    driver.get(line[0])
    time.sleep(10)


f.close()

... the following message was raised:

"selenium.common.exceptions.InvalidArgumentException: Message: invalid argument"

Appreciate your help and patience in explaining what had actually gone wrong :)

Don't use an index with line, just do:

for line in reader:
    Driver.get(line)

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