-2

I have started programming in python not too long ago and I came across with a problem for which I got stuck. I try to download (called export the button on the page) a csv file to my desktop from this page: http://kapar.mavir.hu/kapar/daily-publication.jsp?locale=hu_HU on a daily basis in python. My problem is that all the solution I found are for pages where the urls change after you push the button but in this case nothing happens with url after the push so the methods don't work as far as I'm concerned. How can I code this one down in python (python 2.7 are in use)?

Any help/suggestions are appreciated.

Thanks in advance.

nyaki
  • 45
  • 1
  • 2
  • 8
  • 5
    What have you tried so far? – ltd9938 Aug 02 '18 at 14:00
  • Assuming you already know how do download "things" be it with `requests` or `urllib` or whatever, the trick is to find the "real" URL that is called when you click the "export" button, in your browser hit `F12` to get the "Dev tools", go to the "Network" tab, click the "export" button you'll see that the actual download link is like this `http://kapar.mavir.hu/kapar/com.astron.kapar.WebClient/download?f=dpu&fr=20180803&to=20180803&l=HU` ... adjust the parameters to your needs. – Lohmar ASHAR Aug 02 '18 at 14:04
  • Try to find the export button in HTLM and then "click" (()button = browser.find_element_by_name("button") button.click()), https://stackoverflow.com/questions/25415405/downloading-an-excel-file-from-the-web-in-python -this answer and other random things I found in youtube. – nyaki Aug 02 '18 at 14:07
  • Thanks. So in theory with the link you gave in urllib or requests should do the trick? – nyaki Aug 02 '18 at 14:11
  • Yes, seems that you should modify the `fr` and `to` parameter to pass the date(s) you want to export. – Lohmar ASHAR Aug 02 '18 at 14:35
  • Ok. Thank you very much for the information. – nyaki Aug 02 '18 at 14:37

1 Answers1

1

Please provide the code you have so far. In the mean time;

find out what URL you need to fetch from if you haven't already (check html for this)

import urllib.request
import urllib.parse

data = urllib.parse.urlencode({...})
data = data.encode('ascii')

with urllib.request.urlopen("http://...", data) as fd:
    print(fd.read().decode('utf-8'))

Also check this post out.

SamAtWork
  • 455
  • 5
  • 17
  • Your Answer is helpful, I'd highly appreciate it, if you could help my similar situation Sam. stackoverflow.com/q/66298758/10939394 – Alekhya varma Feb 23 '21 at 19:43