syntax-error?
Stefan Antoni
sasoft at gmx.de
Fri Nov 23 19:34:58 EST 2001
I got the following script and it produces a syntax error which drives
me crazy. it says:
File "<string>", line 24
j = 0 # a counter
^
SyntaxError: invalid syntax
Why?
is j = 0 invalid?
here's the script (anybody who can help me?):
import httplib
# request the page and get it
def GetUrl(ServerAdr, PagePath):
http = httplib.HTTP(ServerAdr)
http.putrequest('GET', PagePath)
http.putheader('Accept', 'text/html')
http.putheader('Accept', 'text/plain')
http.endheaders()
httpcode, httpmsg, headers = http.getreply()
if httpcode != 200:
raise "Could not get document: Check URL and Path"
doc = http.getfile()
data = doc.read()
doc.close()
return data
# parse the page and return the content between the start and end token
def ExtractData(in_string, start_line, end_line):
lstr = in_string.splitlines()
j = 0 # a counter
for i in lstr:
j = j+1
if i.strip() == start_line: slice_start = j # find slice start
elif i.strip() == end_line: slice_end = j # find slice end
return lstr[slice_start:slice_end] # return the slice
# handle the returned stuff and generate a new page
def main():
# parameter and constants
ServerAdr = 'www.onlinekosten.de'
PagePath = '/'
StartLine = '<head>'
EndLine = '</head>'
Head1 = ''
Head2 = ''
Foot = ''
# call functions
RawData = GetUrl(ServerAdr, PagePath)
v = ExtractData(RawData, Startline, EndLine)
# return result and construct page
print Head1.strip() + ServerAdr.strip() + Head2.strip()
for i in v:
print i.strip()
print Foot.strip()
if __name__ == '__main__':
main()
--
thx in advance,
Stefan Antoni
----------------------------
Fre Nov 23 19:31:54 EST 2001
More information about the Python-list
mailing list