Python > Selenium + CSV : Webdriver to read, 访问 .csv 文件中的所有链接

标签 python selenium csv selenium-webdriver

这个问题是关于使用网络驱动程序(“ChromeDriver”,Selenium)来:

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

我编写了一个简单的代码:

from selenium import webdriver
import time
import csv

driver = webdriver.Chrome()

假设link.csv包含以下站点:
• 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()

...提出了以下消息:

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

感谢您在解释实际问题时的帮助和耐心:)

最佳答案

不要将索引与行一起使用,只需这样做:

for line in reader:
    Driver.get(line)

关于Python > Selenium + CSV : Webdriver to read, 访问 .csv 文件中的所有链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59519210/

相关文章:

python - 将年转换为年月日 python pandas csv

python - 为 vim 添加 python 支持

javascript - Nightwatch - 在导航栏中抓取嵌套按钮

python - 我试图以 headless (headless)模式打开一个站点,但它似乎陷入了一个激进的循环,我该如何解决?

python - 需要在 python 中比较 1.5GB 左右的非常大的文件

mysql - 在没有设置任何数据库的情况下,如何将 CSV 文件转换为基于 Web 的 SQL 数据库表?

python - pip:尝试从拉取请求安装时出现 "Reference is not a tree"错误

python - 使用 pdb 的条件断点

selenium - Selenide 结合了 2 个 ElementsCollections

java - Csv:搜索字符串并替换为另一个字符串