从网站自动下载 XLS 文件

发布于 2025-01-08 12:14:00 字数 96 浏览 2 评论 0原文

如何从网站自动下载 XLS 文件? 我的客户输入用户名和密码登录网站,然后我需要一一下载 XLS 文件列表并将它们保存到一个路径中。文件链接位于 html 表内。 需要你们的帮助

How can I download XLS files from a website automatically?
My client enters user name and password for login into the website and from then i need to download list of XLS files, one by one and saved them into one path. the files link are inside a html table.
need your help guys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

杀お生予夺 2025-01-15 12:14:00

您可以通过以下方式执行此操作...浏览器行为有所不同,但您可以在每个操作中启动许多文件的下载。我认为这是浏览器中可能拥有的最佳解决方案。

您可以创建一组临时的隐藏 iframe,通过其中的 GET 或 POST 启动下载,等待下载开始并删除 iframe:

<!DOCTYPE HTML>
<html>
<body>
  <button id="download">Download</button> 

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script type="text/javascript">

     $('#download').click(function() {
       download('http://nogin.info/cv.doc','http://nogin.info/cv.doc');
     });

     var download = function() {
       for(var i=0; i<arguments.length; i++) {
         var iframe = $('<iframe style="visibility: collapse;"></iframe>');
         $('body').append(iframe);
         var content = iframe[0].contentDocument;
         var form = '<form action="' + arguments[i] + '" method="GET"></form>';
         content.write(form);
         $('form', content).submit();
         setTimeout((function(iframe) {
           return function() { 
             iframe.remove(); 
           }
         })(iframe), 2000);
       }
     }      

  </script>
</body>
</html>

You can do it in the following way... Browser behaviour differs, but you can initiate downloading of many files per one action. I think this is the best possible solution you might have in a browser.

You can create a temporary set of hidden iframes, initiate download by GET or POST inside of them, wait for downloads to start and remove iframes:

<!DOCTYPE HTML>
<html>
<body>
  <button id="download">Download</button> 

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script type="text/javascript">

     $('#download').click(function() {
       download('http://nogin.info/cv.doc','http://nogin.info/cv.doc');
     });

     var download = function() {
       for(var i=0; i<arguments.length; i++) {
         var iframe = $('<iframe style="visibility: collapse;"></iframe>');
         $('body').append(iframe);
         var content = iframe[0].contentDocument;
         var form = '<form action="' + arguments[i] + '" method="GET"></form>';
         content.write(form);
         $('form', content).submit();
         setTimeout((function(iframe) {
           return function() { 
             iframe.remove(); 
           }
         })(iframe), 2000);
       }
     }      

  </script>
</body>
</html>
自控 2025-01-15 12:14:00

一种廉价且简单的方法是设置 Web 浏览器控件并使用它来登录。您现在拥有该站点的凭据。然后,使用按钮触发每个 XLS 文件的 URI,使用相同的上下文打开,然后保存到驱动器。

您实际上可以对用户隐藏该控件。

由于您似乎控制了该站点,因此我还会考虑使用不同的方法来服务这些位,例如 WCF 服务。

One cheap and easy way is to set up the web browser control and use it to log in. You now have credentials for the site. Then, have a button fire off the URIs for each of the XLS files, opening using the same context, and then save to the drive.

You can actually hide the control from the user.

Since you appear to be in control of the site, I would also consider using a different methodology to serve these bits, like a WCF service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文