Search code examples
pythonhtmlparsingresponseurllib

How to send a response on the site by Python?


I need to send the response to the captcha to the site https://www.list-org.com/bot.

Here's html code of POST-request:

<form name="frm" method="POST">Вы слишком часто обращались к сайту и мы хотим убедиться, что вы не робот.<br>Повторите текст на картинке и сможете дальше работать:<br><br><img src="/kcap.php?PHPSESSID=iahvgmjcb93a0k7fqrf43sq9sk"><br><br><input type="text" name="keystring" autofocus=""><br><br><input type="submit" value=" Проверить! " name="submit"></form>enter code here

This is the part of the code that characterizes the response input field:

<input type="text" name="keystring" autofocus="">

This is the part of the code that characterizes the button:

<input type="submit" value=" Проверить! " name="submit">

How can I use urllib or request libraries to fill in the response field and click on the button?

P.S. I can translate Russian messages if necessary :)


Solution

  • You can use this example how to send POST request to the site:

    import requests
    
    
    url = 'https://www.list-org.com/bot'
    headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0'}
    
    data = {
        'keystring': 'xxx', # <--- put your string here
        'submit': '+Проверить!+'
    }
    
    with requests.session() as s:
        # load PHPSESSID cookie:
        s.get(url, headers=headers)
        r = s.post(url, headers=headers, data=data)
    
        print(r.text)   # print response