dsfsfs 发表于 2018-9-3 06:49:45

Powershell v3 来下载vmare vForum 2013虚拟大会收藏资料

  2013年10月30-10月31日,Vmare召开了vforum2013虚拟大会,在虚拟大会中自己标记收藏的资料会以邮件的方式提供,收到邮件后,看到的是这样的内容。

  好吧,我实在不想一个个点击连接去下载资料,所以看了下邮件中的资料连接,是有规律性的http://vforum2013.cloud-expo.com.cn/?mod=down_doc&id=247,这种连接使用迅雷批量下载,结果尝试了下,结果下载的全是index.htm等文件,文件大小为1kb

  看来还是得靠自己想办法了,之前了解过powershellv3中多了个命令invoke-webrequest,似乎可以用来下载文件,测试了,于是有了下面的代码。
$a="http://vforum2013.cloud-expo.com.cn/?mod=down_doc&id={0}"  

$parentPath="d:\vforum"  

function download-file{  

    param(  

      $id  

    )  

    $b=Invoke-WebRequest ($a -f $id)  

if($b.RawContentLength -gt 0){  

      $ext=$b.Headers.Item("content-type").split("/")  

      $filename="$parentPath\$id.$ext"  

      Set-Content -Encoding Byte -Value $b.Content -Path $filename  

      $filename  

    }  

}  

220..600|%{download-file $_}  

  下面是下载结果,哈哈,当然也有不完美的地方,PDF标题都是数字,下一步我将尝试使用Python中的pdf模组抓取PDf标题或者关键信息,来为PDF改名字。



页: [1]
查看完整版本: Powershell v3 来下载vmare vForum 2013虚拟大会收藏资料