Using python to achieve baidu hi automatic login code

  • 2020-04-02 09:46:14
  • OfStack


# _*_ coding:utf-8 _*_
# name login_baidu.py
import urllib,urllib2,httplib,cookielib
def auto_login_hi(url,name,pwd):
    url_hi="http://passport.baidu.com/?login"
    # Set up the cookie
    cookie=cookielib.CookieJar()
    cj=urllib2.HTTPCookieProcessor(cookie)
    # Set login parameters 
    postdata=urllib.urlencode({'username':name,'password':pwd})
    # Generate a request 
    request=urllib2.Request(url_hi,postdata)
    # Log on to baidu 
    opener=urllib2.build_opener(cj)
    f=opener.open(request)
    print f
    # Open the baidu HI Space page 
    hi_html=opener.open(url)
    return hi_html
if __name__=='__main__':
    name='hjkll'
    password='11111111'
    url='http://hi.baidu.com/ewayfly'
    h=auto_login_hi(url,name,password)
    print h.read()

Related articles: