在python中,您如何使变量在f'中划分一系列数字,这些数字被插入并一一运行
我是编码世界的新手,所以也许有人可以帮助我。甚至可能是一个直接的问题。 目前,我正在使用Selenium和Python进行一个项目,但是到目前为止,我找不到任何有用的东西。 是否可以将F弦中的变量定义为一系列数字范围,这些数字插入了一个占位符,以便一个人可以单独检查每个F字符串?那是我到目前为止得到的。对于“ Terital”的每个值,“ Wunschliste”的范围应在8-18之间。第一个4,然后7岁,依此类推。
while not BuBu:
try:
Wunschliste = range(8-18)
tertial = '4,7,10'
Wunsch1 = Wu1 = browser.find_element_by_xpath(f"/html/body/div[7]/div[2]/div/table/tbody/tr{Wunschliste}]/td[{tertial}]/img")
Wu1.click()
print("Wunsch1 eingeloggt")
browser.find_element_by_class_name("pj_nicht_buchbar")
print("nope")
time.sleep(3)
除:...
谢谢!希望这是有道理的
I'm pretty new to the coding world, so maybe someone can help me. Might even be a straight forward problem.
Currently I'm using selenium and python for a project, but I can't find anything helpful so far.
Would it be possible to define the variables in a f-string as a range of numbers which are inserted in the placeholder one by one so selenium can check each f string seperately? Thats what I got so far. The range of "Wunschliste" is supposed to be between 8-18 for each of the values of "terital". First 4 then 7 and so on.
while not BuBu:
try:
Wunschliste = range(8-18)
tertial = '4,7,10'
Wunsch1 = Wu1 = browser.find_element_by_xpath(f"/html/body/div[7]/div[2]/div/table/tbody/tr{Wunschliste}]/td[{tertial}]/img")
Wu1.click()
print("Wunsch1 eingeloggt")
browser.find_element_by_class_name("pj_nicht_buchbar")
print("nope")
time.sleep(3)
except: ...
Thanks! Hope it makes sense
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以编写嵌套的 for 循环来处理每种情况:
范围是从 8 到 19,因为最后处理的数字将为 18。
You can write nested for-loops to handle each case:
The range is from 8 to 19 because then last handled number would be 18.
range()函数返回给定范围之间给定数字的顺序。
此外,
tertial
似乎是整数
的列表。因此,在将它们传递到XPath中时,您必须将它们转换为字符串字符,并且可以使用以下解决方案:
range() function returns the sequence of the given number between the given range.
Moreover,
tertial
seems to be a list ofintegers
.So while passing them within the xpath you have to convert them into string characters and you can use the following solution: