<p>我有xpath来跟踪selenium网站上的用户。到目前为止,我的想法是:</p>
<pre><code>followloop = [1,2,3,4,5,6,7,8,9,10]
for x in followloop:
driver.find_element_by_xpath("/html/body/div[7]/div/div/div[2]/div[>>>here is where i want the increment to increase<<<]/div[2]/div[1]/div/button").click()
</code></pre>
<p>所以我在代码中声明的地方就是我希望数字递增的地方。同样,正如你在for循环中看到的,Im'正在做1,2,3,4,5…我能把它编码得更简单一些吗?因为我不只是想要1-10,我会想要1-无论是更高的数字。在</p>
<p>我试着把x放在我想要的地方,但是我意识到python不会发现它是我想放在那个槽中的一个变量,只会把它当作xpath的一部分。那么我如何使它在每个循环中,把递增的数字变量放入其中呢?在</p>
<p>我将使用通配符“%s”作为您的任务和range(),如前面的注释所示:</p>
<pre><code>for x in range(0,100):
driver.find_element_by_xpath("/html/body/div[7]/div/div/div[2]/div[%s]/div[2]/
div[1]/div/button").click() % x
</code></pre>