0

I have application which pulls lottery numbers from official website of lottery.

Website allows search previous lottery games by its date.

I have tried it by using requests module but after request was sent I still receiving website output before submit.

Could take a look and guide me what I am doing wrong?

import requests
import datetime

web_page = 'https://www.lotto.pl/lotto/wyniki-i-wygrane/wyszukaj'

def import_lotto():

    date = datetime.datetime(2019, 3, 2).strftime('%Y-%m-%d')

    payload = {
        'data_losowania[date]': date,
        'id': 'wyszukaj-wyniki-submit'
    }

    response = requests.post(web_page, data=payload)

    with open("requests_results.html", 'w') as f:
        f.write(response.text)


if __name__ == '__main__':
    import_lotto()
MrDominikku
  • 76
  • 1
  • 4
  • 13
  • Is there any JavaScript involved? If it's not rendered on the server, requests won't see it. – jonrsharpe Nov 03 '19 at 07:57
  • From looking at the website linked, the results from filling out the form only come in after a POST request is made to a certain URL (check the 'action' tag on the form in the website). What you might want to do is send that POST request yourself and parse the returned value as the website does in the javascript. – anerisgreat Nov 03 '19 at 08:04
  • @anerisgreat Look at my edit, I have changed to `requests.post` and passed data parameters based on https://stackoverflow.com/questions/13147914/how-to-simulate-http-post-request-using-python-requests-module but it's still giving empty output. – MrDominikku Nov 12 '19 at 18:36

0 Answers0