0

how to get post request on this website?

here I have trouble getting post requests such as urls and post data, because I use a smart phone so I can't get it, anyone can get it, the url and post data are okay.

this is the website

https://www.upiqrcode.com/iban-generator/de/germany

I want the data section to be filled in like this when on the website

Select Country: Germany

Bank Code (8 Digits .i.e. 37040044 ): 37040044

Bank Account No. ( 10 digits i.e. 0532013000): 0532013034

import requests

url = ""

datas = {}

GetInfo = requests.post(url, data=datas)

decodeResponse = GetInfo.content.decode("utf-8")

print(decodeResponse)
  • 1
    When you run your Python script, what was the _trouble_? I got an error `requests.exceptions.MissingSchema: Invalid URL '': No schema supplied. Perhaps you meant http://?`. You should [edit] your question and add this. – hc_dev Aug 08 '21 at 10:46
  • I only asked to get post requests such as api and post data on the website I mentioned earlier, that's all. – Nancy Savchenko Aug 08 '21 at 10:50
  • 1
    can you get it, by opening developer mode in your browser. – Nancy Savchenko Aug 08 '21 at 10:51

2 Answers2

2

Even if you define the url properly by assigning the given URL:

import requests

url = "https://www.upiqrcode.com/iban-generator/de/germany"
datas = {}
GetInfo = requests.post(url, data=datas)
decodeResponse = GetInfo.content.decode("utf-8")

print(decodeResponse)

You would end up getting HTML as response, which correctly prints on console.

Record the form-submission and watch POST request in browser

Instead, figure out how and where the form-data is POSTed. Do this by opening the browsers Developer Console (usually F12) and viewing the Network tab, before clicking submit button (here "Calculate") on the form.

Firefox Network Monitor to show POST request

You can even right-click on the request there an Copy > as CURL. Then paste that in a text-editor or on the command-line to reproduce.

curl 'https://www.upiqrcode.com/get-iban-number' \
-H 'User-Agent: Mozilla/0.0 (OS) Gecko/20210808 Firefox/0.0' \
-H 'Accept: text/html, */*; q=0.01' \
-H 'Accept-Language: en-US,en;q=0.5' --compressed \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Origin: https://www.upiqrcode.com' \
-H 'Connection: keep-alive' \
-H 'Referer: https://www.upiqrcode.com/iban-generator/de/germany' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-GPC: 1' \
--data-raw 'country=DE&bank=37040044&branch=&account=0532013000&ip=0.0.0.0'

Note: I have broken into several lines for readability (thus the \ at line ends). For privacy protection I have anonymized data like User-Agent and IP in the request above.

Even when anonymized like this, the request sent via cURL on the command-line, you get a response (HTML snippet) with the expected IBAN:

<h4 class="text-center text-success">IBAN Electronic Format :DE89370400440532013000</h4><h4 class="text-center text-success">IBAN Paper Format :DE89 3704 0044 0532 0130 00 </h4>

Reproduce in Python

Now you can rebuild this POST-request in Python.

What we need is:

  • some request-headers like 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
  • the posted data: 'country=DE&bank=37040044&branch=&account=0532013000&ip=0.0.0.0'
hc_dev
  • 8,389
  • 1
  • 26
  • 38
  • why don't the results come out – Nancy Savchenko Aug 08 '21 at 11:06
  • this part is not coming out, do you have any suggestions.

    IBAN Electronic Format :DE89370400440532013000

    IBAN Paper Format :DE89 3704 0044 0532 0130 00

    the result above does not come out
    – Nancy Savchenko Aug 08 '21 at 11:17
  • @NancySavchenko Sure, this part is coming out of the CURL request. I left it to you, to code the request in Python. A tutorial for [POSTing forms with requests](https://realpython.com/python-requests/) or [research on SO](https://stackoverflow.com/questions/20759981/python-trying-to-post-form-using-requests) – hc_dev Aug 08 '21 at 11:24
  • oh now the results are out, thank you for your help – Nancy Savchenko Aug 08 '21 at 11:33
  • @NancySavchenko Welcome, that's what Stackoverflow is about. Please contribute back and try improving your question (title, formatting, spelling/grammar, etc.), so it can be found and helps others ️ – hc_dev Aug 08 '21 at 12:13
0

Please refer Mr.hc_dev asnwer to know how i got URL

import requests

url = "https://www.upiqrcode.com/get-iban-number"
replace_with_your_ip = ""
datas = {
    "country":"DE",
    "bank":"37040044",
    "account":"0532013034",
    "ip":replace_with_your_ip,
}

GetInfo = requests.post(url, data=datas)

decodeResponse = GetInfo.content.decode("utf-8")

print(decodeResponse)

To remove HTML content

import re

def remove_tags(text):
    comp = re.compile(r'<[^>]+>')
    return comp.sub('', text)

print(remove_tags(decodeResponse))

Or with BeautifulSoup

from bs4 import BeautifulSoup
soup = BeautifulSoup(decodeResponse,"html.parser")
for i in soup.find_all("h4"):
    print(i.text)

O/P

IBAN Electronic Format :___ Paper Format :___ 
Rinshan Kolayil
  • 1,111
  • 1
  • 9
  • 14