天天看點

python模拟登陸“春秋航空”官網+手動輸入驗證碼

# coding:utf8

import requests

#識别驗證碼轉換資料
def captcha(captcha_data):
    with open("chunqiu.jpg","wb") as f:
        f.write(captcha_data)
    text=raw_input("輸入驗證碼:")
    return text

def chunqiuLogin():
    # 建構一個session對象,可以儲存cookie
    sess=requests.Session()
    headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36",
             "Connection": "keep-alive"}
    # html = sess.get("https://account.flycua.com/sso/index.htm?returnUrl=http://www.flycua.com/member/member-login!loginJump.shtml", headers=headers).text
    
    # 驗證碼url固定不變
    image_url ="https://account.flycua.com/sso/chineseVerifyCode.images"

    #發送圖檔的請求擷取圖檔資料流
    captcha_data=sess.get(image_url,headers=headers).content

    #擷取驗證碼裡的文字,需要手動輸入
    text=captcha(captcha_data)
        
#保護個人隐私,賬号密碼是虛構的,需要填寫真實的      
data={ "loginUser":"1111111111", "password":"8116189", "verifyCode":text, } #先post相關登陸需要的參數,模拟登陸 response=sess.post("https://account.flycua.com/sso/login.htm",data=data,headers=headers) #輸出是否登陸成功 print response.text # 擷取陶然的個人首頁 response=sess.get("https://m.flycua.com/h5/user/index.html",headers=headers) print response.text # 将爬取的首頁轉換HTML,生成my.html檔案 # with open("my.html","w") as f: # f.write(response.text.encode("utf-8"))if __name__ == "__main__": chunqiuLogin()
上一篇: asktom
下一篇: HOJ Funfair