Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584965

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:55:54+00:00 2026-06-11T21:55:54+00:00

I am getting Traceback (most recent call last): File <stdin>, line 2, in <module>

  • 0

I am getting

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
IndexError: list index out of range

Error whenever i am trying to run this code. i am just trying to print all the URL’s on this page. Can please someone tell me ,what i am doing wrong??

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.tour-india.net/best-of-india.htm")
cities=browser.find_elements_by_css_selector(".posts1>a>h2")
for i in range(0,len(cities)):
    cities1=browser.find_elements_by_css_selector(".posts1>a>h2")[i]
    cities1.click()
    title=browser.find_elements_by_xpath("//title")
    content=browser.find_elements_by_css_selector(".tours_text_innerpage.content_margin_top")
    currentUrl=browser.current_url
    print currentUrl
    browser.back()

Edit:
I was making some modifications in the code
I added cities=browser.find_elements_by_css_selector(“.posts1>a>h2”) again after for loop and suddenly Index Error stopped coming. Now i am confused why it happened.??

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.tour-india.net/best-of-india.htm")
cities=browser.find_elements_by_css_selector(".posts1>a>h2")
for i in range(0,len(cities)):
    cities=browser.find_elements_by_css_selector(".posts1>a>h2")
    cities1=browser.find_elements_by_css_selector(".posts1>a>h2")[i]
    cities1.click()
    title=browser.find_elements_by_xpath("//title")
    content=browser.find_elements_by_css_selector(".tours_text_innerpage.content_margin_top")
    currentUrl=browser.current_url
    print currentUrl
    browser.back()

Edit: my Entire Traceback

>>> import traceback
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
>>> browser.get("http://www.tour-india.net/best-of-india.htm")
>>> cities=browser.find_elements_by_css_selector(".posts1>a>h2")
>>> for i in range(0,len(cities)):      
...     try:
...             #cities=browser.find_elements_by_css_selector(".posts1>a>h2")
...             cities1=browser.find_elements_by_css_selector(".posts1>a>h2")[i]
...             cities1.click()
...             title=browser.find_elements_by_xpath("//title")
...             content=browser.find_elements_by_css_selector(".tours_text_innerpage.content_margin_top")
...             currentUrl=browser.current_url
...             print currentUrl
...             browser.back()
...     except:
...             print traceback.format_exc()
... 
http://www.tour-india.net/golden-triangle.htm
http://www.tour-india.net/golden-triangle-varanasi.htm
http://www.tour-india.net/magnificent-rajasthan.htm
http://www.tour-india.net/northindia-rajasthan-tour.htm
http://www.tour-india.net/north_india_himalaya_tour.htm
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
IndexError: list index out of range

http://www.tour-india.net/southindia-panorma.htm
http://www.tour-india.net/classical-rajasthan-tours.htm
http://www.tour-india.net/rajasthan-forts.htm
http://www.tour-india.net/india-nepal-tour.htm
http://www.tour-india.net/southindia-glimpses.htm
http://www.tour-india.net/enchanting-southindia.htm
http://www.tour-india.net/shekhawati-tours.htm
http://www.tour-india.net/delhi-tour.htm
http://www.tour-india.net/bombay-goa.htm
http://www.tour-india.net/royal-rajasthan.htm
http://www.tour-india.net/grand-mughal.htm
http://www.tour-india.net/north_india_himalaya_tour.htm
http://www.tour-india.net/northindia-images.htm
http://www.tour-india.net/karnataka-heritage.htm
http://www.tour-india.net/leh-ladakh.htm
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
IndexError: list index out of range

http://www.tour-india.net/darjeeling-sikkim.htm
http://www.tour-india.net/himalayan-heritage.htm
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
IndexError: list index out of range

http://www.tour-india.net/rajasthan-goa.htm
http://www.tour-india.net/rajasthan-forts-palaces.htm
http://www.tour-india.net/rajasthan-mp.htm
http://www.tour-india.net/rajasthan-nepal.htm
http://www.tour-india.net/splendid-gujarat.htm
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Related Questions

I am getting Traceback (most recent call last): File <stdin>, line 2, in <module>
I'm getting this error Traceback (most recent call last): File /home/<username>/flup/server/fcgi_base.py, line 558, in
Why am I getting no attribute __getitem__ error for dictionary: Traceback (most recent call
computer@computer:~/android/froyo$ repo init -u https://android.googlesource.com/platform/manifest -b froyo Traceback (most recent call last): File "/home/computer/bin/repo",
I am new to Python and am getting this error: Traceback (most recent call
So I'm getting this error: import smtplib server = smtplib.SMTP() server.connect() Traceback (most recent
I keep getting this error for a portion of my code. Traceback (most recent
elif(listb[0] == "-test"): run_all.set("testview") listb.pop[0] ERROR : Exception in Tkinter callback Traceback (most recent
Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have
Getting ERR_CONNECTION_RESET after more or less 2 minutes of uploading a rather big file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.