首页 > 解决方案 > 驱动程序没有导航到其中包含列表项的 url

问题描述

Selenium 没有使用列表项导航到 url,它给了我一个错误

这是代码中不起作用的部分:

driver.get("https://www.dropbox.com/search/work?path=%2F&query=",*list_of_lists[listposition])

完整代码:

...
# add list to list
a_file = open("C:/Users/Unknown/Documents/dropbox/find_this.txt", "r")

list_of_lists = []
for line in a_file:
  stripped_line = line.strip()
  line_list = stripped_line.split()
  list_of_lists.append(line_list)

a_file.close()

listtotal = len(list_of_lists)

print("Total:", listtotal)

# create list
links = []

# set position
listposition = 0

while listposition < listtotal:

    driver.get("https://www.dropbox.com/search/work?path=%2F&query=",*list_of_lists[listposition])
    sleep(5)
...

这是文本文件“find_this.txt”中的列表项:

42508
48157
44179
44597
48156
32250
48160
33343
48162
41628
36063
41983
36064
47438
40941
48165

标签: python-3.xselenium-webdriver

解决方案


driver.get(url)只接受一个参数。

我看到你想连接字符串,请这样做:

while listposition < listtotal:
    driver.get("https://www.dropbox.com/search/work?path=%2F&query=" +list_of_lists[listposition])

...

或使用.format加括号{}

driver.get("https://www.dropbox.com/search/work?path=%2F&query={}".format(list_of_lists[listposition]))

推荐阅读