溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python如何實現(xiàn)的登錄與提交表單數(shù)據(jù)功能

發(fā)布時間:2021-04-06 10:33:59 來源:億速云 閱讀:254 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下python如何實現(xiàn)的登錄與提交表單數(shù)據(jù)功能,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

具體如下:

# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
import os
import time
import requests, requests.utils, pickle
try:
  import cookielib # 兼容Python2
except:
  import http.cookiejar as cookielib
s=requests.session()
print s.headers
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# with open('cook.txt', 'r') as f:
#  cookies = json.loads(f.read())
# print cookies
# try:
#   with open("cookies.txt", "r") as f:
#     load_cookies = json.loads(f.read())
#   s.cookies = requests.utils.cookiejar_from_dict(load_cookies)
#   print s.get('https://fms.lvchengcaifu.com/welcome').content
# except:
#
url = "https://oauth3.lvchengcaifu.com/login"
headers={
  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
}
r= s.get(url,headers=headers,verify=False)
r=r.text
print r
print type(r)
r = r.encode('unicode-escape')
print type(r)
p = re.compile('.*_csrf"\s+value="(.*?)".*')
m = p.match(r)
token = m.group(1)
print token
headers={
  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'csrf_token': token
}
imgurl='https://oauth3.lvchengcaifu.com/Kaptcha.jpg'
r = s.get(imgurl)
r = r.content
# print s
print type(r)
print r
filename = 'E:\image.jpg'
local = open(filename, 'wb')
local.write(r)
local.close()
print "登錄二維碼已經(jīng)下載到本地" + "[" + filename + "]"
 ##打開圖片
os.system("start %s" % filename);
code = raw_input('輸入驗證碼: ')
print code
print len(code)
## <input type="hidden" id="_csrf" name="_csrf" value="6f772fd9-14da-40c4-b317-e8d9a4336203" />
login_url='https://oauth3.lvchengcaifu.com/login/form'
data = {'username': '1111', 'password': '2222@', '_csrf': token,'validCode':code}
response = s.post(login_url, data=data,headers=headers)
print response.content
aa=s.cookies
print '-------------------------------------'
print aa

python如何實現(xiàn)的登錄與提交表單數(shù)據(jù)功能

看完了這篇文章,相信你對“python如何實現(xiàn)的登錄與提交表單數(shù)據(jù)功能”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI