Skip to content

Instantly share code, notes, and snippets.

@muzizongheng
Created July 18, 2013 06:03
Show Gist options
  • Save muzizongheng/6027013 to your computer and use it in GitHub Desktop.
Save muzizongheng/6027013 to your computer and use it in GitHub Desktop.
create http post by using Request
#build request for login url
#post data
postdata = {
'u':username,
'p':password,
'remember':'1',
't':'log',
'f':urllib.parse.quote(moduleUrl),
}
postdata = urllib.parse.urlencode(postdata).encode('utf-8')
print(postdata)
req = urllib.request.Request(
url = csdnLoginUrl,
data = postdata)
req.add_header('Accept', 'text/html, application/xhtml+xml, */*');
req.add_header('Accept-Language', 'en-US')
req.add_header('Accept-Encoding', 'gzip, deflate')
req.add_header('Connection', 'Keep-Alive');
req.add_header('Referer', csdnAccessModuleUrl)
req.add_header('User-Agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)');
#open login url
r = urllib.request.urlopen(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment