Forked from rafaelhdr/Python urllib2.urlopen like Chrome
Created
October 21, 2019 17:30
-
-
Save AmesianX/8ac1d4f3aa0ca9bb7e186f8b87e597c3 to your computer and use it in GitHub Desktop.
Make a urlopen on Python with headers like Chrome
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 urllib2 | |
link = "http://example.com" | |
r = urllib2.Request(url=link) | |
# r.add_header('Cookie', 'sessionid=13cxrt4uytfc6ijvgeoflmb3u9jmjuhil; csrftoken=jdEKPN8iL62hdaq1hmMuID9DMALiiDIq') | |
r.add_header('Upgrade-Insecure-Requests', '1') | |
r.add_header('Accept-Encoding', 'gzip, deflate, sdch, br') | |
r.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36') | |
r.add_header('Connection', 'keep-alive') | |
r.add_header('Cache-Control', 'max-age=0') | |
r.add_header('Accept-Language', 'en-US,en;q=0.8,pt;q=0.6') | |
r.add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8') | |
response = urllib2.urlopen(r) | |
print(response.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment