www.webdeveloper.com
Page 4 of 4 FirstFirst ... 234
Results 46 to 55 of 55

Thread: Save an HTML table as CSV

  1. #46
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    I have been tinkering with VBS on this issue. I have a script that kinda-sorta works, and what doesn't seem to work is very puzzling. When I get back to the office I will post the script for your review... if you're so inclined. Thank you for being so patient and helpful with this.

  2. #47
    Join Date
    Mar 2009
    Posts
    495
    If all else fails, you can always do the trick of dynamically adding a script tag to the page which in reality sends data to an active program, as in

    Code:
    var head = document.getElementsByTagName('head');
    var notAJAX = document.createElement('script');
    notAJAX.src = "http://whereEver.com/destination.php&myData=stuffToBeSent";
    head.appendChild(notAJAX);
    It does have all the limitations of any GET call, but you don't have any "common origin" problems.

  3. #48
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    Tcobb - Where in the script does this belong, and what else would I need to edit? It appears I would simply put this at the beginning of the HTML file to run on the local machine and simply edit the notAJAX.src URL. Am I missing anything else here?

  4. #49
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    Here is the portion of the VBS that is not working. For some reason, CTRL+A doesn't execute. Any thoughts as to what might be going wrong?

    Code:
    wscript.sleep (10000)Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys "admin"
    WshShell.SendKeys "{TAB}"
    WshShell.SendKeys "xPr3$$"
    WshShell.SendKeys "{ENTER}"
    wscript.sleep (4000)
    WshShell.SendKeys "^{a}"
    WshShell.SendKeys "^{c}"
    WshShell.SendKeys "^{w}"

  5. #50
    Join Date
    Mar 2009
    Posts
    495
    This may be, and probably is, of no value to you whatsoever. I have never really been completely clear on the topology of your setup. I take it that:

    1. The information that you want to grab and transmit is funneled through the server on the local network, which does not itself have access to the internet.

    2. Your laptop computer has access both to the local network and the internet as well.

    3. You have some control over the local server. You could add some javascript to the page which contains the table.

    --If you have answered no to any of these questions, ignore the rest of this post.

    As far as using dynamically generated script tags to send cross-domain information, here is an example.

    HTML:
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    
    <script>
    var scr;
    
    function zap(input){
       var head = document.getElementsByTagName('head');
       head = head[0];
       scr = document.createElement('script');
       scr.defer = true;
       scr.src = "http://127.0.0.1/zzz.php" + '?data=' + input;
       head.appendChild(scr);
    }
    
    window.onload = function(){  //extract data from page and send to server
       var z = document.getElementById('d1');
       zap(z.innerHTML);
    }
    </script>
    </head>
    <body>
    <div id="d1"> FRED </div>
    </body>
    </html>
    Notice it is calling for something other than a static js file. And although the example references a php script on the local computer it can really access it at any domain where the script resides.

    PHP:

    Code:
    <?php
    $str = 'alert("Hello ' . $_GET["data"] . '");';
    echo($str);
    ?>
    The main thing is that the server's response must be some valid javascript. The example here extracts data from the page, sends that to the server, which processes it like any form data, and then sends some javascript back. And there are problems with doing this. Its an imperfect substitute for AJAX, and you do need the server to cooperate to send anything back.

  6. #51
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    I have fixed the VBS by adding sleep commands after each CTRL+X SendKeys. I now have a CSV of the data from the stalist.cgi page.

  7. #52
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    869
    Well it looks like VBS is turning out to be a real hero for your problems.

    Are you able to import the CSV yourself or do you need some scripting for that?
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  8. #53
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    I really appreciate all your help. I'm taking a stab at importing the CSV's and I've already made some progress. The problem I'm going to have is having the script cycle through all the CSV's in a folder for import, then deleting all files after upload.

  9. #54
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    Now comes the fun part... putting everything where it belongs.

    I have attached the script I am using to import the information from the CSV into the MySQL database. My goals:

    • Get the file name for entry into the database (I can pass this in the URL if needed)
    • Remove the erroneous three rows at the top of each CSV file (two blank rows and one header row)
    • Have the script cycle through and execute for all CSV's in the directory
    • Delete the CSV's after being imported


    My thought is that the individual laptops will run the script to get the data from stalist.cgi and upload the CSV every hour. Then, half-past every hour, this script will run that imports all CSV files into the database. This gives the computers time to process and upload and ensure I have the most accurate data possible.

    Here is the script I have started with. As you can tell, I am specifying one particular CSV file to be read. I haven't figured out a way to have the script execute for all files. TIMTACULAR is the name of my computer, so you can see that the computer name is used the filename. It makes no difference to be whether the file name, or computer name (via URL) is used.

    Code:
    <?php
    
    $link_id = mysql_connect("localhost", "**", "***") or die("Could not connect."); if(!mysql_select_db("speedtest",$link_id)) die("database was not selected.");
    
    
    $file_handle = fopen("resultupload/TIMTACULAR.csv", "r");
    
    
    while (($line_of_data = fgetcsv($file_handle, 1000, ",")) !== FALSE) { $line_import_query="INSERT into bridges(MAC,DeviceName,SignalNoiseDBM,Distance,TxRxMbps,CCQ,ConnectionTime,LastIP) values('$line_of_data[0]','$line_of_data[1]','$line_of_data[2]','$line_of_data[3]','$line_of_data[4]','$line_of_data[5]','$line_of_data[6]','$line_of_data[7]')"; mysql_query($line_import_query) or die(mysql_error()); 
    }
    
    
    
    
    ?>
    http://timweitzel.net/wasp/TIMTACULAR.csv - Link to the actual CSV file being saved.
    http://timweitzel.net/wasp/rxbridge.PNG - List of Columns in the database

  10. #55
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    I can see where this portion needs to be in a PHP forum. I will copy it there as to not confuse people. Hopefully this will help other developers along the way.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles