Skip to content

Instantly share code, notes, and snippets.

@maakcode
Last active December 12, 2018 04:12
Show Gist options
  • Save maakcode/c1e73d1b5ad08de7ecb714c28e604516 to your computer and use it in GitHub Desktop.
Save maakcode/c1e73d1b5ad08de7ecb714c28e604516 to your computer and use it in GitHub Desktop.
[python3] #python3
brew unlink python3
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
brew switch python3.6.5
import pycurl
import urllib
from StringIO import StringIO
html = StringIO()
referer = "<a href="http://example.com" target="_blank">http://example.com</a>"
url = "<a href="http://example.com" target="_blank">http://example.com</a>"
cookieFile = "Cookie_File_Name.cookie"
userAgent = "UserAgentData"
formFields = {"user_choice":"user_choice value"}
curl = pycurl.Curl()
curl.setopt(pycurl.USERAGENT, userAgent)
curl.setopt(pycurl.HEADER, 0)
curl.setopt(pycurl.TIMEOUT, 120)
curl.setopt(pycurl.COOKIEFILE, cookieFile)
curl.setopt(pycurl.COOKIEJAR, cookieFile)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.REFERER, referer)
curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(formFields))
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.WRITEFUNCTION, html.write)
curl.perform()
effectiveUrl = curl.getinfo(pycurl.EFFECTIVE_URL) #actual webpage url
httpCode = curl.getinfo(pycurl.HTTP_CODE) #http error code
curl.close()
print html.getvalue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment