批处理之家's Archiver

gflrlm 发表于 2018-3-17 21:49

抓取btrenren电影网站上的torrent下载链接需要给invoke-restmethod传递post参数的构造

[i=s] 本帖最后由 gflrlm 于 2018-3-17 22:09 编辑 [/i]

比如访问 [url= [url]http://www.btrenren.com/index.php/Dow/index.html?id=17072&zz=1[/url]]
模拟点击“点击下载”按钮 ,需要进行如下操作:

####################################################################################
### 下面是上面网页的源代码 ,关键内容如下,需要构$body 数据给 -post 参数
### 实际上,不需要再访问上面的网址, 只需要根据 id 和zz 构造出body即可下载了。
[font=Arial] ### view-source: [url]http://www.btrenren.com/index.php/Dow/index.html?id=17072&zz=1[/url]
###      # <form action="" method="post">
###      # <input type="hidden" value="17072" name="id">
###      # <input type="hidden" value="zz1" name="zz">
###      # <input name="imageField" type="image" width="140" height="55" src="http://www.btrenren.com/Public/Home/images/download.gif" style="cursor:pointer;">
###      # </form>[/font]
###
####################################################################################[code]
$body = @{
     "zz"="zz1"          ### <input type="hidden" value="download"
     "id"="17072"        ### <input type="hidden" value="17072" #output torrent file
     "id"="23681"        ### <input type="hidden" value="23681" #redirect to a new web html

}
$torrent_filename="xxxxx.torrent"
注意下面的uri 网址 http://www.btrenren.com/index.php/Dow/index.html ,取自源代码里面皿form action = ""
  invoke-restmethod -uri http://www.btrenren.com/index.php/Dow/index.html -Body $body -Method Post -OutFile $torrent_filename
[/code]有时候对torrent文件进行命名的时候,我们需要根据抓到的网页里面的title进行命名,比如 $torrent_filename= "[color=Red][BT下载][狼吻夜惊魂][HD-MP4/1.8GB][中文字幕][1080P][/color]"       

[u]<span><a href="http://www.btbtt88.com/thread-index-fid-1-tid-14215.htm"><title ="[color=Red][BT下载][狼吻夜惊魂][HD-MP4/1.8GB][中文字幕][1080P][/color]"</a></span>
[/u]

此时会提示错误: -outfile 通配符 路径不存在 。 这个时候需要将里面的特殊字符 [ ] : ? 等替换掉 , 使用下面的函数:[code]
  function escape_wildcards_to____string([string] $s) {
   $s1 = $s -replace '\[','___'
   $result = $s1 -replace '\]','___'
   $result = $result -replace '\*','___'
   $result = $result -replace '\?','___'
   $result = $result -replace '\/','___'
   $result = $result -replace '\\','___'
   $result = $result -replace '\:','___'
   return $result
}

[/code]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.