Python 正在尝试使用webbrowser.open打开某些页面
这是我的密码:Python 正在尝试使用webbrowser.open打开某些页面,python,python-webbrowser,Python,Python Webbrowser,这是我的密码: import time import webbrowser for k in range(3): webbrowser.open("[Censured]index=k") time.sleep(5) print("Téléchargement du fichier numéro", k) 所以我想做的是打开网页[谴责]索引=1。然后,[谴责]指数=2,谴责]指数=3等等。。。但我不明白如何在这段代码中更改变量k 它打开URL[Censured]inde
import time
import webbrowser
for k in range(3):
webbrowser.open("[Censured]index=k")
time.sleep(5)
print("Téléchargement du fichier numéro", k)
所以我想做的是打开网页[谴责]索引=1。然后,[谴责]指数=2,谴责]指数=3等等。。。但我不明白如何在这段代码中更改变量k
它打开URL[Censured]index=k,如果我将第4行更改为webbrowser.open(“[Censured]index=,k)
,则是相同的问题
我怎样才能解决这个问题
webbrowser.open("[Censured]index="+str(k))
会把工作做完的!!如果所有假设的细节都是正确的,比如链接等
您的方法不起作用的原因是,在第一种情况下,当您将[code>“[Censured]index=k”作为参数传递时,它将被视为一个完整的字符串,并且k的值无论如何都不会更改,例如:
for i in range(5):
print "The number is i"
for i in range(5):
print "ContinuousSequence",i
Output:
>>> ContinuousSequence 0 #notice the extra space between them.
>>> ContinuousSequence 1
>>> ContinuousSequence 2
>>> ContinuousSequence 3
>>> ContinuousSequence 4
输出将是:
>>> The number is i
>>> The number is i
>>> The number is i
>>> The number is i
>>> The number is i
在第二种情况下,当您尝试“[Censured]index=,k
,则逗号运算符在连接两个结果时隐式放置了一个空格,这将不会生成有效的超链接。例如:
for i in range(5):
print "The number is i"
for i in range(5):
print "ContinuousSequence",i
Output:
>>> ContinuousSequence 0 #notice the extra space between them.
>>> ContinuousSequence 1
>>> ContinuousSequence 2
>>> ContinuousSequence 3
>>> ContinuousSequence 4