Python Forum

Full Version: single range function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey I need help to create multiple loops in a single statement as:

'''for n1,n2,n3 in range(1,501):
........code'''

**TypeError: cannot unpack non-iterable int object**
What exactly do you mean? What would you expect that code to do if it were possible to write it? Also, why do you need to do something like this? Please give details so people can help you find appropriate solutions.
(Oct-05-2020, 08:04 AM)ndc85430 Wrote: [ -> ]What exactly do you mean? What would you expect that code to do if it were possible to write it? Also, why do you need to do something like this? Please give details so people can help you find appropriate solutions.
I need the code to extract data from the web, however the problem is related to creating a single range statement.

for n1, n2 , n3, n4, n5 in range(1,501):
  buyer=browser.find_element_by_xpath('/html/body/form/div[4]/div[5]/div/div[4]/table/tbody/tr['f'{n1}'']/td[4]/a')
    buyer=buyer.text
    seller=browser.find_element_by_xpath('/html/body/form/div[4]/div[5]/div/div[4]/table/tbody/tr['f'{n2}'']/td[5]/a')
    seller=seller.text
and so on
range will yield one number at a time (i.e. per each iteration). That said it's still not clear what you want to achieve.
Is it correct to assume you actually want to get
1, 2, 3, 4, 5
then
6, 7, 8, 9, 10
and so on?