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()
3
  • Is there any JavaScript involved? If it's not rendered on the server, requests won't see it. Commented Nov 3, 2019 at 7: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. Commented Nov 3, 2019 at 8:04
  • @anerisgreat Look at my edit, I have changed to requests.post and passed data parameters based on stackoverflow.com/questions/13147914/… but it's still giving empty output. Commented Nov 12, 2019 at 18:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.