April 11th, 2005, 05:19 AM
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?
April 11th, 2005, 07:37 AM
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.
April 11th, 2005, 09:10 AM
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
for lines in open('C:\\PATH\\179.htm').readlines():
if ' (Format\Size)' in lines:
April 11th, 2005, 12:57 PM
You can use the find() method of a string class to find the next "\n" from a starting position.
doc = """
(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
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
April 12th, 2005, 06:22 AM
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
pos = doc.find("(Format\Size)")
pos2 = doc.find('\n', pos)
pos3 = doc.find('</TD>', pos2)
labelref = doc[pos2:pos3]
posnext = doc.find("(Format\Size)", pos3)
pos4 = doc.find('\n', posnext)
pos5 = doc.find('</TD>', pos4)
labelref2 = doc[pos4:pos5]