Skip to content

Instantly share code, notes, and snippets.

@victor-iyi
Created August 27, 2017 14:11
Show Gist options
  • Save victor-iyi/a76bfe0ddb3cd39d49f466ea8c29fa99 to your computer and use it in GitHub Desktop.
Save victor-iyi/a76bfe0ddb3cd39d49f466ea8c29fa99 to your computer and use it in GitHub Desktop.
Retrieve source code for any given URL
import urllib.request
import urllib.parse
def get(url):
try:
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
req = urllib.request.Request(url, headers=headers)
reqeust = urllib.request.urlopen(req)
resp = request.read().decode()
return resp
except Exception as e:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment