for i in range(1, 1000):
print("/html/body/div[6]/div/div/div[2]/div/div/div['+ i + '/div[3]/button']")
I want it to print as in the example, what should I do?
/html/body/div[6]/div/div/div[2]/div/div/div**[1]**/div[3]/button']
/html/body/div[6]/div/div/div[2]/div/div/div**[2]**/div[3]/button']
/html/body/div[6]/div/div/div[2]/div/div/div**[3]**/div[3]/button']
/html/body/div[6]/div/div/div[2]/div/div/div**[4]**/div[3]/button']
/html/body/div[6]/div/div/div[2]/div/div/div**[5]**/div[3]/button']
/html/body/div[6]/div/div/div[2]/div/div/div**[6]**/div[3]/button']
A few ways to format the print string.
Method 1:
for i in range(1, 10):
print(f"/html/body/div[6]/div/div/div[2]/div/div/div[{i}]/div[3]/button']")
Method 2:
for i in range(1, 10):
print("/html/body/div[6]/div/div/div[2]/div/div/div[%s]/div[3]/button']" % (i, ))
Method 3:
for i in range(1, 10):
print("/html/body/div[6]/div/div/div[2]/div/div/div[{0}]/div[3]/button']".format(i, ))
Reference: https://docs.python.org/3/library/string.html?highlight=string#format-string-syntax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With