消息关闭
    暂无新消息!

python+requests 网页重定向求解

问题作者 : 速度2017-05-04发布

网址 https://jobs.jnj.com/apply/17...

hed={
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive',
'Content-Type':'application/json; charset=UTF-8',
'Cookie':'fsr.r={"d":90,"i":"d445cf0-83485980-db18-f9ef-2a23d","e":1493111295590}; survey_cx=1; _ga=GA1.2.2063062824.1491810947; __atuvc=12%7C15%2C1%7C16; aui=undefined; pjuid=XXXXXXXXX%40qq.com; session_id=b87db789-5a01-4282-a8d8-1ab488243c6c; _ga=GA1.3.2063062824.1491810947; _janalytics_id.25ab=77683f5d-3bdd-475a-85db-1f2fe2d886d6.1491810985.21.1493019790.1493015356.db055a7d-2148-4142-8033-f42016d19136; _janalytics_ses.25ab=*; jrasession=a37d1ff7-c655-4d28-aac6-13d02b96364d; msid=7931948b-7eb3-4d16-8c18-11b985383059; i18n=zh-CN; jasession=s%3Amca76N35xpszvFHwc-IIys4yFsEf5rCB.eqhOpE0uHYgPRfMzbyRwFPUHbM9nmW7tjzMzzLvAg6g; mp_55bff8dc262c60239ef050f320f194cc_mixpanel=%7B%22distinct_id%22%3A%20%2215b56dd0e751db-07cf638be06fea-4e45062e-100200-15b56dd0e764f%22%2C%22%24initial_referrer%22%3A%20%22http%3A%2F%2Fwww.careers.jnj.com%2Fzh-hans%22%2C%22%24initial_referring_domain%22%3A%20%22www.careers.jnj.com%22%7D; mp_mixpanel__c=0',
'Host':'jobs.jnj.com',
'Origin':'https://jobs.jnj.com',
'Referer':'https://jobs.jnj.com/apply/1700160876W/login',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
url="https://jobs.jnj.com/mirror_event"
data={"event":"accept","sync_id":"8f318696-db4c-4acf-a422-91269a4bd7b0","inputs":{}}

html=requests.post(url=url,headers=hed,data=json.dumps(data))
print ("!!!!!!!",html.text)
print (html.status_code)

返回结果是:

!!!!!!! {"session":"COMPLETE","sync_id":"a23fbaa2-2d1f-4309-8a12-34c740bd93cd","redirect_to":"https://jobs.jnj.com/mirror/session/success?user_id=XXXXXXXXXX%40qq.com&username=XXXXXXXXX%40qq.com"}
200

求解怎么才能得到如图返回值:


1个回答

︿ 0
# coding: utf-8

import requests

headers = {
    'Cookie': 'session_id=3675761f-5f36-4028-bb7e-b417df5f8d44; _janalytics_id.25ab=9119551b-40bd-4256-aabe-09787be3728a.1493084550.2.1493097922.1493084550.4f311a7b-7f08-4402-bcca-824ad42ecc77; _janalytics_ses.25ab=*; _ga=GA1.3.610663176.1493084552; _gat=1; jrasession=34d71257-1e76-43c4-94e9-28e6861ae878; msid=5292a0f0-5207-423f-8ce2-53addec5f643; i18n=zh-CN; jasession=s%3ArSoKyR6H5YeTQonjAoMGvIYP3AlPVy48.RbVlAJbaSkevIzLX%2FRuiN2gu%2FgVYtcPuyWydxQTV%2BcY; mp_55bff8dc262c60239ef050f320f194cc_mixpanel=%7B%22distinct_id%22%3A%20%2215ba2c63c46df9-008636491d19dc-39687804-fa000-15ba2c63c47def%22%2C%22%24initial_referrer%22%3A%20%22https%3A%2F%2Fsegmentfault.com%2Fq%2F1010000009176817%22%2C%22%24initial_referring_domain%22%3A%20%22segmentfault.com%22%7D; mp_mixpanel__c=0',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
}

data = {"event":"accept","sync_id":"bc790202-6dcf-4981-8f43-060c49849126","inputs":{}}
r = requests.post('https://jobs.jnj.com/mirror_event', json=data, headers=headers)
print r.text