3.1 Accessing Text from the Web and from Disk

Electronic Books A small sample of texts from Project Gutenberg appears in the NLTK corpus collection. However, you may be interested in analyzing other texts from Project Gutenberg. You can browse the catalog of 25,000 free online books at http://www.gutenberg.org/cata log/, and obtain a URL to an ASCII text file. Although 90% of the texts in Project Gutenberg are in English, it includes material in over 50 other languages, including Catalan, Chinese, Dutch, Finnish, French, German, Italian, Portuguese, and Spanish (with more than 100 texts each). Text number 2554 is an English translation of Crime and Punishment, and we can access it as follows. >>> from urllib import urlopen >>> url = “http://www.gutenberg.org/files/2554/2554.txt” >>> raw = urlopen(url).read() >>> type(raw) >>> len(raw) 1176831 >>> raw[:75] ‘The Project Gutenberg EBook of Crime and Punishment, by Fyodor Dostoevsky\r\n’

Leave a Reply