Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Retrieving data from a webpage

Retrieving data from a webpage

Scheduled Pinned Locked Moved C#
csharpdotnetagentic-aihelp
10 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MAW30
    wrote on last edited by
    #1

    I am trying to retreive data from a webpage with a label saying "export". The data is partially showing on the screen, if I manually click on "export" a window comes up and ask to save, save as, or cancel. I then save all data to my computer as a csv file. However when trying to get the data using c# I get the code behind "export" and not the data, code starts out as "". I am using the following code:

    WebClient webClient = new WebClient();
    webClient.UseDefaultCredentials = false;
    webClient.Credentials = new NetworkCredential(strUsername, strPassword);
    webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
    webClient.DownloadFile(url, @strOutputFile);

    *note url is for "export". Can someone please point me in the right direction. Any help will be greatly appreciated. Thanks in advance. Michael

    D M 2 Replies Last reply
    0
    • M MAW30

      I am trying to retreive data from a webpage with a label saying "export". The data is partially showing on the screen, if I manually click on "export" a window comes up and ask to save, save as, or cancel. I then save all data to my computer as a csv file. However when trying to get the data using c# I get the code behind "export" and not the data, code starts out as "". I am using the following code:

      WebClient webClient = new WebClient();
      webClient.UseDefaultCredentials = false;
      webClient.Credentials = new NetworkCredential(strUsername, strPassword);
      webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
      webClient.DownloadFile(url, @strOutputFile);

      *note url is for "export". Can someone please point me in the right direction. Any help will be greatly appreciated. Thanks in advance. Michael

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Are you trying to get the page HTML or some specific data from it?

      "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

      M 1 Reply Last reply
      0
      • D dan sh

        Are you trying to get the page HTML or some specific data from it?

        "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

        M Offline
        M Offline
        MAW30
        wrote on last edited by
        #3

        I am trying to get the csv file full of data not the html code.

        D 1 Reply Last reply
        0
        • M MAW30

          I am trying to get the csv file full of data not the html code.

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          OK, and I assume the URL in the DownloadFile method ends with CSV. Is that correct?

          "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

          M 1 Reply Last reply
          0
          • D dan sh

            OK, and I assume the URL in the DownloadFile method ends with CSV. Is that correct?

            "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

            M Offline
            M Offline
            MAW30
            wrote on last edited by
            #5

            yes

            D 1 Reply Last reply
            0
            • M MAW30

              yes

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              One thing might be happening here is that the website expects you to reach to file from the page where the button is. Can you add appropriate (that page's URL) referrer header to your request and check?

              "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

              M 1 Reply Last reply
              0
              • D dan sh

                One thing might be happening here is that the website expects you to reach to file from the page where the button is. Can you add appropriate (that page's URL) referrer header to your request and check?

                "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

                M Offline
                M Offline
                MAW30
                wrote on last edited by
                #7

                The following is the website: "http://finviz.com/screener.ashx?v=150&ft=4" however you have to pay for the service to get data, which will be "http://elite.finviz.com/screener.ashx?v=150&ft=4". Find the button export the url on that is "http://elite.finviz.com/export.ashx?v=150&ft=4" This is the actual url I use then add or don't add ".csv". if I enter the url in my browsers command line, the file is downloaded, but when I use c# I get html code.

                1 Reply Last reply
                0
                • M MAW30

                  I am trying to retreive data from a webpage with a label saying "export". The data is partially showing on the screen, if I manually click on "export" a window comes up and ask to save, save as, or cancel. I then save all data to my computer as a csv file. However when trying to get the data using c# I get the code behind "export" and not the data, code starts out as "". I am using the following code:

                  WebClient webClient = new WebClient();
                  webClient.UseDefaultCredentials = false;
                  webClient.Credentials = new NetworkCredential(strUsername, strPassword);
                  webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                  webClient.DownloadFile(url, @strOutputFile);

                  *note url is for "export". Can someone please point me in the right direction. Any help will be greatly appreciated. Thanks in advance. Michael

                  M Offline
                  M Offline
                  MAW30
                  wrote on last edited by
                  #8

                  Can anybody else possibly help with this. Thanks in advance, Michael

                  L 1 Reply Last reply
                  0
                  • M MAW30

                    Can anybody else possibly help with this. Thanks in advance, Michael

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    What is the exact URI that you are using for the download?

                    M 1 Reply Last reply
                    0
                    • L Lost User

                      What is the exact URI that you are using for the download?

                      M Offline
                      M Offline
                      MAW30
                      wrote on last edited by
                      #10

                      I solved the problem with help from the website, I needed to add authorization into the url. Thanks, Michael

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups