尝试做一个简单的 post 并获取请求,仍然出现错误

Trying to make a simple post and get request, still getting error

我正在尝试抓取网页,但无法访问使用该服务动态加载的端点。我检查了网络选项卡并找到了服务并尝试模拟请求,但出现错误 enter image description here

尝试使用具有相同负载的查询参数发出获取请求,出现 http 400 错误。请有人帮忙!

我附上了图片,请大家帮忙看看!

代码如下

import requests
payload = {'doctorId':'739559',
       'regdNovalue':'3608'}
headers = {'Accept': '*/*',
          'Accept-Encoding': 'gzip, deflate, br',
          'Accept-Language': 'en-US,en;q=0.9',
          'Connection': 'keep-alive',
          'Content-Length': '42',
          'Content-Type': 'application/json',
          'Cookie': 'JSESSIONID=-jU0dgec3PJUA- 
           bjaUtO3aPvIUnX2Zz4I31sRlrX.web3; 
           PHPSESSID=0lmo0b9av7vob0m66c1ugtm840',
          'Host': 'www.nmc.org.in',
          'Origin': 'https://www.nmc.org.in',
          'Referer': 'https://www.nmc.org.in/information-desk/indian- 
           medical-register/',
          'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="101", 
          "Google Chrome";v="101"',
          'sec-ch-ua-mobile': '?0',
          'sec-ch-ua-platform': '"Windows"',
          'Sec-Fetch-Dest': 'empty',
          'Sec-Fetch-Mode': 'cors',
          'Sec-Fetch-Site': 'same-origin',
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
           AppleWebKit/537.36 (KHTML, like Gecko) 
           Chrome/101.0.4951.67 Safari/537.36',
          'X-Requested-With': 'XMLHttpRequest'}

url = "https://www.nmc.org.in/MCIRest/open/getDataFromService?service=getDoctorDetailsByIdImr"
res1 = requests.get(url, params = payload,headers=headers)
res2 = requests.post(url, data = payload,headers=headers)

TIA

要从服务器获取数据,使用json=参数:

import json
import requests

api_url = "https://www.nmc.org.in/MCIRest/open/getDataFromService"
params = {"service": "getDoctorDetailsByIdImr"}
payload = {"doctorId": "17068", "regdNoValue": "3608"}

data = requests.post(api_url, params=params, json=payload).json()

# pretty print the data:
print(json.dumps(data, indent=4))

打印:

{
    "yearInfo": 1981,
    "regDate": "24/03/1981",
    "doctorId": 17068,
    "salutation": null,
    "firstName": "Jagtap Shailendra",
    "middleName": null,
    "lastName": null,
    "phoneNo": null,
    "emailId": null,
    "gender": null,
    "bloodGroup": null,
    "parentName": "Lata Raghunath Jagtap",
    "birthDate": null,
    "isNewDoctor": false,
    "checkExistingUser": false,
    "birthDateStr": null,
    "birthPlace": null,
    "nationality": null,
    "eligbleToVote": null,
    "adharNo": null,
    "uprnNo": null,
    "doctorEducationId": null,
    "college": null,
    "doctorDegree": "MBBS",
    "university": "U.Indore",
    "otherSubject": null,
    "monthOfPass": null,
    "yearOfPassing": "1980",
    "smcId": 15,
    "registrationDate": null,
    "registrationNo": "3608",
    "smcName": "Madhya Pradesh Medical Council",
    "homeAddress": null,
    "officeAddress": null,
    "address": "1 / 10, New Palasia Indore, M. P. ",
    "officeaddress": null,
    "addressLine1": "1 / 10, New Palasia Indore, M. P. ",
    "addressLine2": null,
    "economicStatus": null,
    "city": null,
    "state": null,
    "country": null,
    "pincode": null,
    "photos": null,
    "doctRegistrationNo": null,
    "universityId_view": null,
    "universityId": null,
    "monthandyearOfPass": "1980",
    "passoutCollege": null,
    "collegeId": null,
    "stateId": null,
    "category": null,
    "category_view": "N/A",
    "role": null,
    "registrationDatePrevious": null,
    "registrationNoPrevious": null,
    "smcNamePrevious": null,
    "uprnNoPrevious": null,
    "removedStatus": false,
    "removedOn": "01/01/1900",
    "restoredStatus": false,
    "restoredOn": "01/01/1900",
    "remarks": null,
    "regnNo": null,
    "smcIds": null,
    "trasanctionStatus": null,
    "addlqual1": "                    ",
    "addlqualyear1": "    ",
    "addlqualuniv1": "                                        ",
    "addlqual2": "                    ",
    "addlqualyear2": "    ",
    "addlqualuniv2": "                                                  ",
    "addlqual3": "                    ",
    "addlqualyear3": "    ",
    "addlqualuniv3": "                                                  ",
    "patientfirstName": null,
    "patientmiddleName": null,
    "patientlastName": null,
    "patientphoneNo": null,
    "patientemailId": null,
    "appealBy": null,
    "altphone": null,
    "landLineNo": null,
    "patientlandLineNo": null,
    "patientaltphone": null,
    "picName": null,
    "signatureName": null,
    "stateMedicalCouncil": null,
    "countryType": null,
    "dateOfBirth": null,
    "universityName": null,
    "qualification": null,
    "imrNumber": null
}