python web page parsing when no HTML tags exist
Question: Got this lovely webpage with nothing but text and I need some help getting
certain lines formatted and also join multiple lines on one line

The web page is <http://www.srh.noaa.gov/data/PHI/SRFPHI>

I need the date of report and everything between these 2 lines:

    
    
      .FOR THE BEACHES OF NEW JERSEY AND DELAWARE... (include this)
      TIDE INFORMATION... (not this line, just prior)
    

Any ideas what to use?


Answer: I load all the lines into a list, and go through that list with a for loop. I
check if `.FOR THE BEACHES OF NEW JERSEY AND DELAWARE` is in that index in the
list, if it is I create a temporary variable called line. I go until line is
the same as `TIDE INFORMATION...`, then it won't print anymore because the if
statement will never be true again.

    
    
    import urllib
    import sys
    
    url = 'http://www.srh.noaa.gov/data/PHI/SRFPHI'
    
    try:
        response = urllib.urlopen(url)
    except:
        print 'Invalid url.'
        sys.exit(1)
    
    data = response.readlines()
    
    for i in range(0, len(data)):
        if '.FOR THE BEACHES OF NEW JERSEY AND DELAWARE' in data[i]:
            date = data[i - 2]
            print date
            line = data[i]
            while line.strip('\n') != 'TIDE INFORMATION...':
                print line
                i = i + 1
                line = data[i]
    

