bookfind 通过ISBN序号获取图书连接的书名与作者的vbs代码
程序员文章站
2022-04-10 08:13:56
核心代码:复制代码 代码如下: if wscript.arguments.unnamed.count <> 1 then syntax if wscript.a...
核心代码:
if wscript.arguments.unnamed.count <> 1 then syntax
if wscript.arguments.named.count > 1 then syntax
blntd = false
if wscript.arguments.named.count = 1 then
if ucase( wscript.arguments.named( 0 ) ) = "/td" then
blntd = true
else
syntax
end if
end if
strisbn = wscript.arguments.unnamed( 0 )
strpgtitle = titlefromhtml( "http://www.amazon.com/gp/product/" & strisbn & "/" )
strpattern = "amazon.com: (.*): books: (.*)$"
strtitle = regexpval( strpattern, strpgtitle, 0 )
strauthor = regexpval( strpattern, strpgtitle, 1 )
if blntd then
strmsg = strisbn & vbtab & strtitle & vbtab & strauthor & vbcrlf
else
strmsg = vbcrlf & "title : " & strtitle _
& vbcrlf & "author : " & strauthor _
& vbcrlf & "isbn : " & strisbn
end if
wscript.echo strmsg
function regexpval( strpattern, strstring, idx )
on error resume next
dim regex, match, matches, retstr
set regex = new regexp
regex.pattern = strpattern
regex.ignorecase = true
regex.global = true
set matches = regex.execute( strstring )
regexpval = matches( 0 ).submatches( idx )
end function
function titlefromhtml( strurl )
set ie = createobject( "internetexplorer.application" )
ie.navigate strurl
do until ie.readystate = 4
wscript.sleep 10
loop
titlefromhtml = ie.document.title
ie.quit
end function
sub syntax
strmsg = strmsg & vbcrlf & "bookfind.vbs, version 1.11" & vbcrlf _
& "display book title and author name for the specified isbn number." & vbcrlf & vbcrlf _
& "usage: cscript //nologo bookfind.vbs isbn [ /td ]" & vbcrlf & vbcrlf _
& "where: ""isbn"" is the isbn (or asin) of the book to search for" & vbcrlf _
& " /td changes the output format to tab delimited" & vbcrlf & vbcrlf _
& "note: this script uses amazon's web site to look up author and title." & vbcrlf _
& " to be precise, the data is extracted from the title of the page" & vbcrlf _
& " with url http://www.amazon.com/gp/product/ followed by the isbn." & vbcrlf _
& " that means this script will fail when amazon changes the urls." & vbcrlf & vbcrlf _
& "written by rob van der woude" & vbcrlf _
& "http://www.robvanderwoude.com"
wscript.echo( strmsg )
wscript.quit( 1 )
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.
复制代码 代码如下:
if wscript.arguments.unnamed.count <> 1 then syntax
if wscript.arguments.named.count > 1 then syntax
blntd = false
if wscript.arguments.named.count = 1 then
if ucase( wscript.arguments.named( 0 ) ) = "/td" then
blntd = true
else
syntax
end if
end if
strisbn = wscript.arguments.unnamed( 0 )
strpgtitle = titlefromhtml( "http://www.amazon.com/gp/product/" & strisbn & "/" )
strpattern = "amazon.com: (.*): books: (.*)$"
strtitle = regexpval( strpattern, strpgtitle, 0 )
strauthor = regexpval( strpattern, strpgtitle, 1 )
if blntd then
strmsg = strisbn & vbtab & strtitle & vbtab & strauthor & vbcrlf
else
strmsg = vbcrlf & "title : " & strtitle _
& vbcrlf & "author : " & strauthor _
& vbcrlf & "isbn : " & strisbn
end if
wscript.echo strmsg
function regexpval( strpattern, strstring, idx )
on error resume next
dim regex, match, matches, retstr
set regex = new regexp
regex.pattern = strpattern
regex.ignorecase = true
regex.global = true
set matches = regex.execute( strstring )
regexpval = matches( 0 ).submatches( idx )
end function
function titlefromhtml( strurl )
set ie = createobject( "internetexplorer.application" )
ie.navigate strurl
do until ie.readystate = 4
wscript.sleep 10
loop
titlefromhtml = ie.document.title
ie.quit
end function
sub syntax
strmsg = strmsg & vbcrlf & "bookfind.vbs, version 1.11" & vbcrlf _
& "display book title and author name for the specified isbn number." & vbcrlf & vbcrlf _
& "usage: cscript //nologo bookfind.vbs isbn [ /td ]" & vbcrlf & vbcrlf _
& "where: ""isbn"" is the isbn (or asin) of the book to search for" & vbcrlf _
& " /td changes the output format to tab delimited" & vbcrlf & vbcrlf _
& "note: this script uses amazon's web site to look up author and title." & vbcrlf _
& " to be precise, the data is extracted from the title of the page" & vbcrlf _
& " with url http://www.amazon.com/gp/product/ followed by the isbn." & vbcrlf _
& " that means this script will fail when amazon changes the urls." & vbcrlf & vbcrlf _
& "written by rob van der woude" & vbcrlf _
& "http://www.robvanderwoude.com"
wscript.echo( strmsg )
wscript.quit( 1 )
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.