IndexError: list index out of range when iterating two webelements lists

后端 未结 3 1285
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 06:09

I am trying to print the result on the terminal but getting this error message:

IndexError: list index out of range

Below is the code, tha

3条回答
  •  旧巷少年郎
    2020-12-12 07:01

    You want to use the index i to iterate over names and address, not the list size

    for i in range(num_page_items):
        print(f"{names[i].text} : {address[i].text}")
    

    Or just loop on both with zip

    for name, ad in zip(names, address):
        print(f"{name.text} : {ad.text}")
    

提交回复
热议问题