Created
August 27, 2017 14:11
-
-
Save victor-iyi/a76bfe0ddb3cd39d49f466ea8c29fa99 to your computer and use it in GitHub Desktop.
Retrieve source code for any given URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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