批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[转贴] VBScript脚本bookfind通过ISBN序号获取图书连接的书名与作者

bookfind 通过ISBN序号获取图书连接的书名与作者的vbs代码,类似小偷程序,通过正则匹配,虽然现在已经无法使用,但代码不错,原理都有

核心代码:

  1. If WScript.Arguments.UnNamed.Count <> 1 Then Syntax
  2. If WScript.Arguments.Named.Count > 1 Then Syntax
  3. blnTd = False
  4. If WScript.Arguments.Named.Count = 1 Then
  5. If UCase( WScript.Arguments.Named( 0 ) ) = "/TD" Then
  6. blnTd = True
  7. Else
  8. Syntax
  9. End If
  10. End If
  11. strISBN = WScript.Arguments.UnNamed( 0 )
  12. strPgTitle = TitleFromHTML( "http://www.amazon.com/gp/product/" & strISBN & "/" )
  13. strPattern = "Amazon.com: (.*): Books: (.*)$"
  14. strTitle = RegExpVal( strPattern, strPgTitle, 0 )
  15. strAuthor = RegExpVal( strPattern, strPgTitle, 1 )
  16. If blnTd Then
  17. strMsg = strISBN & vbTab & strTitle & vbTab & strAuthor & vbCrLf
  18. Else
  19. strMsg = vbCrLf & "Title : " & strTitle _
  20. & vbCrLf & "Author : " & strAuthor _
  21. & vbCrLf & "ISBN : " & strISBN
  22. End If
  23. WScript.Echo strMsg
  24. Function RegExpVal( strPattern, strString, idx )
  25. On Error Resume Next
  26. Dim regEx, Match, Matches, RetStr
  27. Set regEx = New RegExp
  28. regEx.Pattern = strPattern
  29. regEx.IgnoreCase = True
  30. regEx.Global = True
  31. Set Matches = regEx.Execute( strString )
  32. RegExpVal = Matches( 0 ).SubMatches( idx )
  33. End Function
  34. Function TitleFromHTML( strURL )
  35. Set ie = CreateObject( "InternetExplorer.Application" )
  36. ie.Navigate strURL
  37. Do Until ie.ReadyState = 4
  38. WScript.Sleep 10
  39. Loop
  40. TitleFromHTML = ie.Document.Title
  41. ie.Quit
  42. End Function
  43. Sub Syntax
  44. strMsg = strMsg & vbCrLf & "BookFind.vbs, Version 1.11" & vbCrLf _
  45. & "Display book title and author name for the specified ISBN number." & vbCrLf & vbCrLf _
  46. & "Usage: CSCRIPT //NOLOGO BOOKFIND.VBS isbn [ /TD ]" & vbCrLf & vbCrLf _
  47. & "Where: ""isbn"" is the ISBN (or ASIN) of the book to search for" & vbCrLf _
  48. & " /TD changes the output format to tab delimited" & vbCrLf & vbCrLf _
  49. & "Note: This script uses Amazon's web site to look up author and title." & vbCrLf _
  50. & " To be precise, the data is extracted from the title of the page" & vbCrLf _
  51. & " with URL http://www.amazon.com/gp/product/ followed by the ISBN." & vbCrLf _
  52. & " That means this script will fail when Amazon changes the URLs." & vbCrLf & vbCrLf _
  53. & "Written by Rob van der Woude" & vbCrLf _
  54. & "http://www.robvanderwoude.com"
  55. Wscript.Echo( strMsg )
  56. Wscript.Quit( 1 )
  57. End Sub
复制代码


使用方法:
CSCRIPT //NOLOGO BOOKFIND.VBS isbn [ /TD ]
Where: "isbn" is the ISBN (or ASIN) of the book to search for
/TD changes the output format to tab delimited
Note: This script uses Amazon's web site to look up author and title.
To be precise, the data is extracted from the title of the page
with URL http://www.amazon.com/gp/product/ followed by the ISBN.
That means this script will fail when Amazon changes the URLs.

http://www.jb51.net/article/29249.htm

返回列表