我想通过使用范围(1,23(将数字从1移动到22来打印你能帮我吗?
number = 1
numf = driver.find_elements_by_xpath('/html/body/div[1]/div/div/div[5]/div[2]/main/section/ul/li[3]/div[2]/div/div[2]/ul/li[%d]/button' %number)
for i in numf:
print(i.text)```
您可以使用以下任一解决方案:
-
使用
%s
:number = 1 numf = driver.find_elements_by_xpath("/html/body/div[1]/div/div/div[5]/div[2]/main/section/ul/li[3]/div[2]/div/div[2]/ul/li[%s]/button"% str(number))
-
使用
format()
:number = 1 numf = driver.find_elements_by_xpath("/html/body/div[1]/div/div/div[5]/div[2]/main/section/ul/li[3]/div[2]/div/div[2]/ul/li[{}]/button".format(str(number)))