1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| """ http://code.t-appagile.com/users/sign_in
http://code.t-appagile.com/users/sign_in """ import requests import json import string from bs4 import BeautifulSoup login = "http://code.t-appagile.com/users/sign_in" call = "http://code.t-appagile.com/users/auth/ldapmain/callback"
headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7', 'Cache-Control': 'no-cache', # 'Content-Length':'183',
'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': '', 'Host': 'code.t-appagile.com', 'Origin': 'http://code.t-appagile.com', 'Proxy-Connection': 'keep-alive',
'Referer': 'http://code.t-appagile.com/users/sign_in', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36', }
def HttpPost(apiUrl, data): try: global headers r = requests.post(apiUrl,headers=headers, data=data) cook = r.request.headers["Cookie"].split('=') lowCook = headers["Cookie"].split('=')
newCook=lowCook[0]+'='+lowCook[1]+'='+cook[2] headers["Cookie"] = newCook print("登陆成功:",newCook) return r except: return
def HttpGet(apiUrl): try: global headers r = requests.get(apiUrl) cook = "" for c in r.cookies: cook += c.name + "="+c.value + ";"
headers["Cookie"] = cook print("登陆前的:",cook) return r.text except: return
def HttpGetLcmm(apiUrl): try: r = requests.get(apiUrl,headers=headers) return r.text except: return
res = HttpGet(login) html = BeautifulSoup(res,"html.parser")
token = html.find_all(type="hidden")[1]["value"]
postData ={} postData["utf8"] ="✓" postData["authenticity_token"] =token postData["username"] ="你的账号" postData["password"] ="你的密码"
res = HttpPost(call,postData)
# print(res.status_code) # print(res.text) # print(html)
res = HttpGetLcmm("http://code.t-appagile.com/SI.Web/lcmm-web") print('ok!')
|