Using the python 'Requests' module for a POST request, getting the response as if it were GET

So, I am trying to make a script that checks for bus redundancy. The source link for this is https://reservation.pc.gc.ca/ .

In the backup unit, you must select the following:

  • Reservation: daily use (guided tours, Lake OHara bus).
  • Park: Yoho Lake O'Hara
  • Arrival Date: June 16
  • Lot Size: 2

When these parameters are entered, you will go to the following page: https://reservation.pc.gc.ca/Yoho-LakeO'Hara? The calendar

I understand that if I send a POST request to this second link with the correct data, it should return the page I'm looking for

If I look in the dev network information settings, when I select the correct parameters, the form data:

__ EventTarget:

__ EVENTARGUMENT: __VIEWSTATE: - full string length -

__ VIEWSTATEGENERATOR: 8D0E13E6

ctl00 $ MainContentPlaceHolder $ rdbListReservationType: Events

ddlLocations: 213a1bc9-9218-4e98-9a7f-0f209008e437 **

ddlArrivalMonth: 2017-06-16

ddlArrivalDay: 19

ddlNights: 1

ddlDepartureMonth:

ddlDepartureDay:

ddlEquipment:

ddlEquipmentSub:

ddlPartySize: 2

ctl00 $ MainContentPlaceHolder $ chkExcludeAccessible: on

ctl00 $ MainContentPlaceHolder $ imageButtonCalendar.x: 64

ctl00 $ MainContentPlaceHolder $ imageButtonCalendar.y: 56

, , , :

import requests

payload = {
        '__EVENTTARGET': '',
        '__EVENTARGUMENT': '',
        '__VIEWSTATE':-reallly long string-,
        '__VIEWSTATEGENERATOR': '8D0E13E6',
        'ctl00$MainContentPlaceHolder$rdbListReservationType': 'Events',
        'ddlLocations': '213a1bc9-9218-4e98-9a7f-0f209008e437',
        'ddlArrivalMonth': 2017-06-16,
        'ddlArrivalDay': 19,
        'ddlNights': 1,
        'ddlDepartureMonth': '',
        'ddlDepartureDay': '',
        'ddlEquipment': '',
        'ddlEquipmentSub': '',
        'ddlPartySize': 2,
        'ctl00$MainContentPlaceHolder$chkExcludeAccessible': 'on',
        'ctl00$MainContentPlaceHolder$imageButtonCalendar.x': 64,
        'ctl00$MainContentPlaceHolder$imageButtonCalendar.y': 56
        }

r = requests.get(r"https://reservation.pc.gc.ca/Yoho-LakeO'Hara?Calendar", data=payload)

print r.text

r.text , , - GET . , , : . . , .

+4
2

, 2 :

  • @errata , POST. .

  • , , , , Home.aspx, URL-, , .

json . /Home.aspx.

Postman, , , .

, .post(), , (, , ): python

, fwiw, Postman. Python, , .

+1

r = requests.get(r"https://reservation.pc.gc.ca/Yoho-LakeO'Hara?Calendar", data=payload)

r = requests.post(r"https://reservation.pc.gc.ca/Yoho-LakeO'Hara?Calendar", data=payload)

, , URL-, , URL- ( HTTP- 302):

$ curl -I "https://reservation.pc.gc.ca/Yoho-LakeO'Hara"
HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 77273
Content-Type: text/html; charset=utf-8
Location: https://reservation-pc.fjgc-gccf.gc.ca/GccfLanguage.aspx?lang=eng&ret=https%3a%2f%2freservation.pc.gc.ca%3a443%2fYoho-LakeO%27Hara
Server: Microsoft-IIS/8.0
Set-Cookie: ASP.NET_SessionId=qw4p4e2zxjxx0c2zyq014p45; path=/; secure; HttpOnly
Set-Cookie: CookieLocaleName=en-CA; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
X-Frame-Options: SAMEORIGIN
Date: Wed, 17 May 2017 14:22:53 GMT

, Location 302:

$ curl -I "https://reservation-pc.fjgc-gccf.gc.ca/GccfLanguage.aspx?lang=eng&ret=https%3a%2f%2freservation.pc.gc.ca%3a443%2fYoho-LakeO%27Hara"
HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 179
Content-Type: text/html; charset=utf-8
Location: https://reservation.pc.gc.ca:443/Yoho-LakeO'Hara?gccf=true
Server: Microsoft-IIS/8.0
Set-Cookie: ASP.NET_SessionId=rbcuvexfg4fb340ixtcjd1qy; path=/; secure; HttpOnly
Set-Cookie: _gc_lang=eng; domain=.fjgc-gccf.gc.ca; path=/; secure; HttpOnly
X-Powered-By: ASP.NET
X-Frame-Options: SAMEORIGIN
Date: Wed, 17 May 2017 14:24:55 GMT

, , , POST GET ...

0

Source: https://habr.com/ru/post/1677355/


All Articles