#-coding:utf-8-*-ImportRequestsImportUrllib fromBs4Importbeautifulsoupheaders={ "user-agent":"mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.75 safari/537.36", "Content-type":"application/x-www-form-urlencoded",} URL="Http://home.51cto.com/index"params={ "Reback":"http://www.51cto.com/", "_CSRF": None,"Loginform[username]":"Account Number", "Loginform[password]":"Password", "Loginform[rememberme]": 0,"Login-button":"Login"}client=requests. Session () Resp=client.get (URL) Soup= BeautifulSoup (Resp.content,"Html.parser") CSRF= Soup.find (attrs={"name":"Csrf-token"})['content']params["_CSRF"] =Csrfparams=Urllib.urlencode (params) Resp= Client.post (URL, Data=params, headers=HEADERS)#Print Resp.content#soup = BeautifulSoup (resp.content, "Html.parser")#For src in soup.find_all ("script"):#Client.get (Src.get ("src"))RESP =client.get (URL)PrintResp.content
Python requets Login 51cto Home