Answer the question
In order to leave comments, you need to log in
Working with strings and types in Python 3?
I need to get a string in a loop, while the counter should be embedded in the middle of the string. As it turned out in python, even the data type cannot be changed. How then to solve such a problem?
i = 1
while i < 11:
t = driver.find_element_by_xpath(".//*[@id='header']/li[" . i(счетчик) . "]/div[2]/div/cite")
print(t)
Answer the question
In order to leave comments, you need to log in
In [1]: for counter in range(1, 11):
...: print(".//*[@id='b_results']/li[{}]/div[2]/div/cite".format(counter))
...:
.//*[@id='b_results']/li[1]/div[2]/div/cite
.//*[@id='b_results']/li[2]/div[2]/div/cite
.//*[@id='b_results']/li[3]/div[2]/div/cite
.//*[@id='b_results']/li[4]/div[2]/div/cite
.//*[@id='b_results']/li[5]/div[2]/div/cite
.//*[@id='b_results']/li[6]/div[2]/div/cite
.//*[@id='b_results']/li[7]/div[2]/div/cite
.//*[@id='b_results']/li[8]/div[2]/div/cite
.//*[@id='b_results']/li[9]/div[2]/div/cite
.//*[@id='b_results']/li[10]/div[2]/div/cite
yes, I agree, some kind of misunderstanding. but pretty :)
for i in xrange(1,11,1):
t = driver.find_element_by_xpath(".//*[@id='b_results']/li[%s]/div[2]/div/cite" %str(i))
print(t)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question