如何使用python通过selenium webdriver从calander中选择随机日期

2024-10-08 20:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用下面的python代码从calander中选择随机日期

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

days = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10','11', '12', '13', '14', '15', '16', '17', '18', '19', '20','21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']

years = ['2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028']

enter image description here

当我运行代码时,它给出了错误webelement is not iterable。你知道吗


Tags: 代码octnovaprjunmarsepmay
1条回答
网友
1楼 · 发布于 2024-10-08 20:21:18

random choice可能就是您想要的:

from random import choice

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
days   = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10','11', '12', '13', '14', '15', '16', '17', '18', '19', '20','21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']
years  = ['2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028']

rand_date = '{}.{}.{}'.format(*map(choice, [days, months, years]))

测试运行:

29.May.2017
28.Feb.2023
10.Feb.2020
29.Jul.2023
4.Feb.2009
3.Jun.2019
22.Jul.2026
5.Apr.2012
7.Dec.2021

相关问题 更多 >

    热门问题