Skip to content

Instantly share code, notes, and snippets.

@rafaelhdr
Last active October 21, 2019 17:30
Show Gist options
  • Save rafaelhdr/a05984cea8f929f29a0c3eb173f8dcdc to your computer and use it in GitHub Desktop.
Save rafaelhdr/a05984cea8f929f29a0c3eb173f8dcdc to your computer and use it in GitHub Desktop.
Make a urlopen on Python with headers like Chrome
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