ISBN -> bookdata Lookup to fill in a database
Ok, I wanting to database a small library.
I've only had limited experience with databases, and none with querying from a webserver.
I'm going to want to retrieve information like title, Publisher, maybe author, description the simplest way I can think of dooing this is looking t开发者_Go百科hem up via the ISBN.
I've come across isbndb.com before, but the API for accessing it seems rather complex.
I'm wondering how I should go about doing this.
This is an incomplete answer, but it should get you started (I've not worked with XML data as return).
This code has the basics:
Dim oHttp As Object
Set oHttp = CreateObject("Microsoft.XMLHTTP")
oHttp.Open "GET", "https://isbndb.com/api/books.xml?access_key=YourKey&results=texts&index1=isbn&value1=YourISBN", False
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHttp.Send vbNullString
Debug.Print oHttp.responseText
The response from the web page is in the .responseText property of the XMLHTTP object. How you process that is beyond me. I know that one of the Access newsgroup gurus has published a tutorial on consuming web services from Access, but I can't locate it. This article might have something to do with the issue:
http://support.microsoft.com/kb/285329/en-us
You can use the MARC21 XML from the Library of Congress.
I did the same thing as you, building a database to house my library. Scanning in the ISBN collects the data from this URL http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=YOUR_ISBN&maximumRecords=1
The response data then fills in a form with all the data. You don't need an account, just that URL.
The response comes in XML (as mentioned), and you can parse from there using whatever language you want (my choice happens to be PHP).
The ISBNdb.com API looks simple. The following request should retrieve the information you want ... just substitute your access key for "YourKey" and the ISBN for "YourISBN".
https://isbndb.com/api/books.xml?access_key=YourKey&results=texts&index1=isbn&value1=YourISBN
The response is XML which contains information about the single book whose ISBN you submitted.
I recently had to do exactly this as we indexed our library for insurance purposes. Below is the code of the vba class I hacked together:
Option Compare Database
dim BookTitle As String
dim BookTitleLong As String
dim BookAuthorsText As String
dim BookPublisherText As String
dim BookSummary As String
dim BookNotes As String
dim accessKey As String
Private Sub Class_Initialize()
'Your isbnDB access key'
accessKey = "PUT ACCESSKEY HERE"
End Sub
Property Get Title() As String
Title = BookTitle
End Property
Property Get TitleLong() As String
TitleLong = BookTitleLong
End Property
Property Get AuthorsText() As String
AuthorsText = BookAuthorsText
End Property
Property Get PublisherText() As String
PublisherText = BookPublisherText
End Property
Property Get Summary() As String
Summary = BookSummary
End Property
Property Get Notes() As String
Notes = BookNotes
End Property
Public Function Lookup(isbn As String) As Boolean
Lookup = False
Dim xmlhttp
Set xmlhttp = CreateObject("MSXML2.xmlhttp")
xmlhttp.Open "GET", "https://isbndb.com/api/books.xml?access_key=" & accessKey & "&results=texts&index1=isbn&value1=" & isbn, False
xmlhttp.send
'Debug.Print "Response: " & xmlhttp.responseXML.XML'
Dim xmldoc
Set xmldoc = CreateObject("Microsoft.XMLDOM")
xmldoc.async = False
'Note: the ResponseXml property parses the server's response, responsetext doesn't
xmldoc.loadXML (xmlhttp.responseXML.XML)
If (xmldoc.selectSingleNode("//BookList").getAttribute("total_results") = 0) Then
MsgBox "Invalid ISBN or not in database"
Exit Function
End If
If (xmldoc.selectSingleNode("//BookList").getAttribute("total_results") > 1) Then
MsgBox "Caution, got more than one result!"
Exit Function
End If
BookTitle = xmldoc.selectSingleNode("//BookData/Title").Text
BookTitleLong = xmldoc.selectSingleNode("//BookData/TitleLong").Text
BookAuthorsText = xmldoc.selectSingleNode("//BookData/AuthorsText").Text
BookPublisherText = xmldoc.selectSingleNode("//BookData/PublisherText").Text
BookNotes = xmldoc.selectSingleNode("//BookData/Notes").Text
BookSummary = xmldoc.selectSingleNode("//BookData/Summary").Text
Lookup = True
End Function
Get an API key, paste the above code (with your key) into a new class module in the VBA editor (Insert->Class Module) and name the module "isbn". You also need to add a reference to "Microsoft XML" in the VBA editor (Tools->References)
You can test it works with the code snippet below in a normal vba module:
Public Function testlookup()
Dim book
Set book = New isbn
book.Lookup ("0007102968")
Debug.Print book.Title
Debug.Print book.PublisherText
End Function
Then just type "testlookup" into the immediate window (View->Immediate Window). You should see a response of:
The Times book of quotations
[Glasgow] : Times Books : 2000.
isbnDB can return more than the data I collect in the above class, read the API reference here: http://isbndb.com/docs/api/ and tailor the class to your needs.
I found this article very helpful in explaining how to use xmlhttp from within access: http://www.15seconds.com/issue/991125.htm
The msdn pages on XML DOM Methods and XMLHttpRequest Object were also useful (because I'm a new user I can only post two active links, you'll have to replace the dots in the urls below):
msdn microsoft com/en-us/library/ms757828(v=VS.85).aspx
msdn microsoft com/en-us/library/ms535874(v=vs.85).aspx
What language are you using? You need a program/script to present a form where you can enter the ISBN, which would then get the data from isbndb.com and populate the database. I've used the API a bit, but not for some time, and it's pretty straightforward.
精彩评论