Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. downloading csv-file from url to local device
Forum Updated to NodeBB v4.3 + New Features

downloading csv-file from url to local device

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 513 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chaki
    wrote on 23 Dec 2020, 18:09 last edited by
    #1

    Hello,
    by using the QNetworkAccessManager Class I am trying to download only the .csv-File from the following URL:
    https://kalender-osterreich.at/feiertage-2020/

    I read the manual, but I am currently reading the whole URL and cannot find out how to download the .csv-file

    void Download::downloading()
    {
    
        manager = new QNetworkAccessManager(this);
        connect(manager, SIGNAL(finished(QNetworkReply*)),
                   this, SLOT(replyFinished(QNetworkReply*)));
    
        manager->get(QNetworkRequest(QUrl("https://kalender-osterreich.at/feiertage-2020/")));
    }
    
    void Download::replyFinished(QNetworkReply *reply)
    {
        if(reply->error())
           {
               qDebug() << "ERROR!";
               qDebug() << reply->errorString();
           }
           else
           {
               QFile *file = new QFile("/somePath/file.csv");
               if(file->open(QFile::Append))
               {
                   file->write(reply->readAll());
                   file->flush();
                   file->close();
               }
               delete file;
           }
    
           reply->deleteLater();
    }
    
    J 1 Reply Last reply 23 Dec 2020, 18:20
    0
    • C Chaki
      23 Dec 2020, 18:09

      Hello,
      by using the QNetworkAccessManager Class I am trying to download only the .csv-File from the following URL:
      https://kalender-osterreich.at/feiertage-2020/

      I read the manual, but I am currently reading the whole URL and cannot find out how to download the .csv-file

      void Download::downloading()
      {
      
          manager = new QNetworkAccessManager(this);
          connect(manager, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(replyFinished(QNetworkReply*)));
      
          manager->get(QNetworkRequest(QUrl("https://kalender-osterreich.at/feiertage-2020/")));
      }
      
      void Download::replyFinished(QNetworkReply *reply)
      {
          if(reply->error())
             {
                 qDebug() << "ERROR!";
                 qDebug() << reply->errorString();
             }
             else
             {
                 QFile *file = new QFile("/somePath/file.csv");
                 if(file->open(QFile::Append))
                 {
                     file->write(reply->readAll());
                     file->flush();
                     file->close();
                 }
                 delete file;
             }
      
             reply->deleteLater();
      }
      
      J Offline
      J Offline
      JonB
      wrote on 23 Dec 2020, 18:20 last edited by JonB
      #2

      @Chaki
      You can't do it like that! The icons to download, which I presume is what you are looking at, don't have URLs identifying the actual document, as you discover by right-clicking on them. So I assume the click action is handled in in-page JavaScript, and you'll have to go investigate that to see what it does. Start with a View Source of the page, and do some judicious searching.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Chaki
        wrote on 23 Dec 2020, 18:27 last edited by
        #3

        @JonB Thank you very much for clarifying Sir!

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fcarney
          wrote on 23 Dec 2020, 19:01 last edited by
          #4
          • Go to the website: https://kalender-osterreich.at/feiertage-2020/
          • click CSV download link
          • download file
          • go to download history in browser
          • copy download link url

          Notice that this link looks like a generated number so the link will most likely expire. This is an indicator that they don't want you to download it programmatically. Contact the owner of the website to find out if they can provide a permanent link to the file so that you can download programmatically. They may or may not provide this. They may have a policy against site scraping. Or they might direct you to an ftp or something similar.

          C++ is a perfectly valid school of magic.

          J 1 Reply Last reply 23 Dec 2020, 19:38
          2
          • C Offline
            C Offline
            Chaki
            wrote on 23 Dec 2020, 19:15 last edited by
            #5

            Thanks for your answer, the download-link is created each with a unique, which expires after the first download itself

            1 Reply Last reply
            0
            • F fcarney
              23 Dec 2020, 19:01
              • Go to the website: https://kalender-osterreich.at/feiertage-2020/
              • click CSV download link
              • download file
              • go to download history in browser
              • copy download link url

              Notice that this link looks like a generated number so the link will most likely expire. This is an indicator that they don't want you to download it programmatically. Contact the owner of the website to find out if they can provide a permanent link to the file so that you can download programmatically. They may or may not provide this. They may have a policy against site scraping. Or they might direct you to an ftp or something similar.

              J Offline
              J Offline
              JonB
              wrote on 23 Dec 2020, 19:38 last edited by
              #6

              @fcarney said in downloading csv-file from url to local device:

              go to download history in browser

              That's cheating ;-) I got blob:https://kalender-osterreich.at/.... What is that blob: protocol?

              1 Reply Last reply
              0

              1/6

              23 Dec 2020, 18:09

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved