python-3.x - 驱动程序没有导航到其中包含列表项的 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
解决方案
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]))
推荐阅读
- php - 使用 Laravel Eloquent 选择多个表
- php - 在自定义编译的 Apache 上安装 PHP 时出错
- c# - 如何使用 FluentValidation 验证 Guid 列表
- python - 熊猫:选择索引,然后选择多索引切片上的列
- intellij-idea - Force push keyboard shortcut in IntelliJ IDEA 2018.1
- html - 如何将模式的第一个字符与其余字符分开?
- r - Fill a polygon with gradient scale in R
- tensorflow - 在带有 AMD Radeon Pro 450 2048 MB 的 Mac High Sierra 10.13.4 上支持 GPU 的 Tensorflow?
- java - 如何将小 ORC 文件合并或合并为更大的 ORC 文件?
- logging - 将日志文件输出到集群选项