python模擬使用者登入某某網

Thinkgamer_gyt發表於2015-09-23

python模擬使用者登入某某網:

#encoding:utf-8  
import urllib2,cookielib  
import re  
  
  
#在網頁登陸成功後的cookies字串  
cookie="|utmccn=(referral)|utmcmd=referral|utmcct=/jira/browse/ONLINEISSU-1131; lk_vuid=136912071869561949; Hm_lvt_de21a9fe270e08ded96c90b71e185e9a=1390376787,1390448036,1390742073,1390891909; ShoppingCart=CartID=2ngFAC5mL6pgjRDoybxULfOj9menHhUaeN8Skf3%2bk0C3qq3aOfc0f9aPnihHsPMB; yt_wstime=2013-06-27 21:54:13; yt_cps_t=gd=f27a12fb-709c-4d29-9858-6dcac1318183&tm=1372341253.22943&s=arrayfung&sn=d1eb0dc723c16d5293e4dd4a3c9216b5; lk__guid=20130826200315188190887988737699876; vizNprd=Wed, 05 Feb 2014 08:05:23 GMT_9; __bfd_session_id=bfd_g=9ba1d4ae5263ccdd000682e200025662518ad734&bfd_s=152740966.43614492.1390742075644&__bfd_tmc=5.152740966.36246088.1390742075646.1390742127729.1390742131567&__bfd_tma=152740966.36246088.1390742075646.1390742075646.1390742075646.1&__bfd_tmd=5.152740966.36246088.1390742075646.; lk__sessionId=1390891900316; s_cc=true; s_sq=%5B%5BB%5D%5D; __utmb=1.5.10.1390891909; __utmc=1; Hm_lpvt_de21a9fe270e08ded96c90b71e185e9a=1390891947; Yt_lg=%2bVAI33Z8Y07pVfF2%2fOMe5HRDMTUIg5megR26nMoCl5G4Mv%2bnuHosq54FC%2bYJJmE0WFSXHKzihVcF2VitTl27jMygvx9xXflsEpIc8u1%2f%2bXFQjcgdPvhashmryiVRv%2b03; Yt_ct=En=wanzhuan2010&VipRank=1&Email=cwg2010%40139.com&OId=D8BE02B73B909F49; CustomerMessage=ShortMessageCount=0"  
  
  
req = urllib2.Request("http://my.yintai.com")  
  
  
# 新增標頭檔案  
req.add_header('Cookie', cookie)  
req.add_header("Content-Encoding","gzip")  
req.add_header("User-Agent",r"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0")  
  
  
content = urllib2.urlopen(req).read()  
  
  
regex = re.compile("登陸")  
  
  
if regex.match(content):  
    print "Login Error"  
else:  
    print "Login Success"  

相關文章