这段代码是一团糟:
import urllib.request
bookName = None
authorName = None
bookStartLine = None
bookEndLine = None
def parser(currentUrl): #parses texts to extract their title, author, begginning line and end line
global bookName
global authorName
global bookStartLine
global bookEndLine
global url
url = 'http://www.gutenberg.org/cache/epub/1232/pg1232.txt' #machiaveli
url = currentUrl
book = urllib.request.urlopen(url)
lines = book.readlines()
book.close()
finalLines = [line.decode()[:-2] for line in lines]
for line in finalLines:
if "Title" in line:
currentBookName = line[7:len(line)]
break
for line in finalLines:
if "Author" in line:
currentAuthorName = line[8:len(line)]
break
currentBookStartLine,currentBookEndLine = False,False
for index,line in enumerate(line,start=1):
if "*** START OF THE PROJECT" in line:
currentBookStartLine = index
if "*** END OF THE PROJECT" in line:
currentBookEndLine = index
url = currentUrl
bookName = currentBookName
authorName = currentAuthorName
bookStartLine = currentBookStartLine
bookEndLine = currentBookEndLine
parser('http://www.gutenberg.org/cache/epub/768/pg768.txt') #wuthering heights
print(url)
print(bookName)
print(authorName)
print(bookStartLine)
print(bookEndLine)