-1

Here on running the following code I am getting an error as below. Can anyone please help me with this.

import urllib
import requests
url = "https://www.sec.gov/Archives/edgar/data/1800/000104746918000856/0001047469-18-000856.txt"
page = urllib.request.urlopen(url).read()
page.decode('utf-8')
text_list = page.decode('utf-8').readlines()

AttributeError: 'str' object has no attribute 'readlines'

Berlin
  • 7
  • 4

2 Answers2

4

It looks like you want an list containing each line of what is returned. This code would do the trick:

import urllib
import requests
url = "https://www.sec.gov/Archives/edgar/data/1800/000104746918000856/0001047469-18-000856.txt"
page = urllib.request.urlopen(url).read()
text_list = page.decode('utf-8').split('\n')
Thomas M
  • 140
  • 1
  • 7
0
page.decode()

returns a string. readlines() works on file objects. So if you had a file object, you would:

linesList = fileObject.readlines()

For more details, see Python readlines description Answer above shows how to still get lines with your decoded page object using delimiters on the string. File objects are not strings, but work like handles to a file which may have strings in it.

user176692
  • 780
  • 1
  • 6
  • 21