#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10

    move to next line


    I am writing an app that reads a html document and looks for various text. When it finds the header i need to move to the next line and will then put that in to a variable. is there a next line command that i can use?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Atlantic City, NJ
    Posts
    327
    Rep Power
    13
    Well, since readlines() returns a list you can search the list for the line you want and then use that lines offset + 1 for the next line.
    I'll learn this stuff someday.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    this is the code i have and this prints the expected line. i now need it to move to the next line and put the data from that line into a variable but keep getting various errors when i try

    Code:
    for lines in open('C:\\PATH\\179.htm').readlines():
          if ' (Format\Size)' in lines:
    		print lines
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    You can use the find() method of a string class to find the next "\n" from a starting position.
    Code:
    doc = """
       Header 1
       (Format Size): 2005
       Body starts here
       Body Line 2
    """
    pos = doc.find("Format Size")
    if pos > 0:
       pos2 = doc.find("\n", pos) # Find the next \n 
       body = doc[pos2+1:]       # and copy the data from there on
    
    print body
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    Many thanks, that worked great.

    I've added the code to search for multiple occurences and add each one to another variable just in case anyone comes accross a similar problem and finds this while searching the forum

    Code:
        pos = doc.find("(Format\Size)")
        if pos>0:
    	pos2 = doc.find('\n', pos)
    	pos3 = doc.find('</TD>', pos2)
    	labelref = doc[pos2:pos3]
    	print labelref
    	posnext = doc.find("(Format\Size)", pos3)
    	if posnext>pos3:
    		pos4 = doc.find('\n', posnext)
    		pos5 = doc.find('</TD>', pos4)
    		labelref2 = doc[pos4:pos5]
    		print labelref2

IMN logo majestic logo threadwatch logo seochat tools logo