title: Python web scraping using BeautifulSoup, Loop and skip certain URL value
body: <p>So I am using following code to scrape statues from a site.</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import requests
  
  
  f = open('C:\Python27\projects\FL_final.doc','w')
  
  base_url = "http://www.leg.state.fl.us/statutes/index.cfm?App_mode=Display_Statute&amp;URL=0000-0099/00{chapter:02d}/00{chapter:02d}.html"
  
  for chapter in range (1,9):
    url = base_url.format(chapter=chapter)
    r = requests.get(url)
    soup = BeautifulSoup((r.content),"html.parser")
    tableContents = soup.find('div', {'class': 'Chapters' })
    for title in tableContents.find_all ('div', {'class': 'Title' }):
      f.write (title.text)
  
     for data in tableContents.find_all('div',{'class':'Section' }):
        data = data.text.encode("utf-8","ignore")
        data = "\n\n" + str(data)+ "\n" 
        f.write(data)
  
  f.close()   
  </code></pre>
  
  <p>the problem is that certain chapters are missing. For example, there are pages for chapter 1 to chapter 2, then page for chapter 3,4,5 doesn't exist. So when use range (1,9) it gives me errors as it cant pick up chapter 3,4,5 contents, as their (0003/0003, 0004/0004, 0005/0005)url dont exist. </p>
  
  <p>How can I skip missing URLs in my loop and let the program find the next available URL within the range?</p>
  
  <p>here is chapter 1's url: <a href="http://www.leg.state.fl.us/statutes/index.cfm?App_mode=Display_Statute&amp;URL=0000-0099/0001/0001.html" rel="nofollow">http://www.leg.state.fl.us/statutes/index.cfm?App_mode=Display_Statute&amp;URL=0000-0099/0001/0001.html</a></p>