[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 5# 523066680


    多谢。你这个方法好像是从文件内容中读取的文件名。如果指向的不是种子文件,而是其他的文件类型比如 exe 就无效了。

TOP

本帖最后由 523066680 于 2016-11-29 11:08 编辑
  1. use Encode;
  2. use LWP::Simple;
  3. my $all = get("https://www.nyaa.se/?page=download&tid=613616");
  4. $all =~ /name\d+:(.*?rar)/i;
  5. print encode('gbk', decode('utf8', $1));
复制代码
海贼王765.rar

补充修改一下:
  1. use Encode;
  2. use LWP::Simple;
  3. my $h = head("https://www.nyaa.se/?page=download&tid=613616");
  4. print encode('gbk', decode('utf8',  $h->{'_headers'}->{'content-disposition'} ))
复制代码
inline; filename="海贼王765.rar.torrent"

TOP

本帖最后由 tmplinshi 于 2016-11-29 10:17 编辑

谢谢二位!

显示的结果是 "海贼�?65.rar.torrent",正确的应该是 "海贼王765.rar.torrent"。
不知道是不是因为 objWinHttp.GetResponseHeader("Content-Disposition") 返回的字符本身就丢失了数据。

TOP

  1. Const adTypeBinary = 1
  2. Const adTypeText = 2
  3. ' accept a string and convert it to Bytes array in the selected Charset
  4. Function StringToBytes(Str,Charset)
  5.   ' Dim Stream
  6.   Set Stream = CreateObject("ADODB.Stream")
  7.   Stream.Type = adTypeText
  8.   Stream.Charset = Charset
  9.   Stream.Open
  10.   Stream.WriteText Str
  11.   Stream.Flush
  12.   Stream.Position = 0
  13.   ' rewind stream and read Bytes
  14.   Stream.Type = adTypeBinary
  15.   StringToBytes= Stream.Read
  16.   Stream.Close
  17.   Set Stream = Nothing
  18. End Function
  19. ' accept Bytes array and convert it to a string using the selected charset
  20. Function BytesToString(Bytes, Charset)
  21.   ' Dim Stream
  22.   Set Stream = CreateObject("ADODB.Stream")
  23.   Stream.Charset = Charset
  24.   Stream.Type = adTypeBinary
  25.   Stream.Open
  26.   Stream.Write Bytes
  27.   Stream.Flush
  28.   Stream.Position = 0
  29.   ' rewind stream and read text
  30.   Stream.Type = adTypeText
  31.   BytesToString= Stream.ReadText
  32.   Stream.Close
  33.   Set Stream = Nothing
  34. End Function
  35. ' This will alter charset of a string from 1-byte charset(as windows-1252)
  36. ' to another 1-byte charset(as windows-1251)
  37. Function AlterCharset(Str, FromCharset, ToCharset)
  38.   Dim Bytes
  39.   Bytes = StringToBytes(Str, FromCharset)
  40. ' HEXS=""
  41. ' for i = 1 to LenB(Bytes)
  42. ' HEXS = HEXS & hex(ascb(MidB (Bytes, i, 1))) & ","
  43. ' next
  44. ' MsgBox HEXS
  45.   AlterCharset = BytesToString(Bytes, ToCharset)
  46. End Function
  47. Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
  48. objWinHttp.Open "HEAD", "https://www.nyaa.se/?page=download&tid=613616"
  49. objWinHttp.Send
  50. MsgBox objWinHttp.GetResponseHeader("Content-Disposition")
  51. ' MsgBox LenB ( objWinHttp.GetResponseHeader("Content-Disposition") )
  52. MsgBox AlterCharset( objWinHttp.GetResponseHeader("Content-Disposition"), "GB2312", "utf-8")
复制代码

TOP

可以使用adodb.stream转码

TOP

返回列表