I am using Python 3.x. While using urllib.request
to download the webpage, i am getting a lot of \\n
in between. I am trying to remove it using the
If you look at the source you've downloaded, the \n
escape sequences you're trying to replace()
are actually escaped themselves: \\n
. Try this instead:
import urllib.request
def download_page(a):
opener = urllib.request.FancyURLopener({})
open_url = opener.open(a)
page = str(open_url.read()).replace('\\n', '')
return page
I removed the try
/except
clause because generic except
statements without targeting a specific exception (or class of exceptions) are generally bad. If it fails, you have no idea why.