ISBN - > bookdata查找填写数据库 [英] 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.
我将要检索像标题信息,发布者,也许作者,描述
我能想到这个dooing的最简单的方法是通过ISBN看着他们。
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 them up via the ISBN.
我遇到isbndb.com之前,但访问它的API似乎相当复杂的。
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.
推荐答案
最近,我不得不这样做正是这一点,因为我们的索引我们的图书馆为保险起见。下面是VBA类我砍死在一起的code:
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
获取API密钥,粘贴上述code(与你的密钥)到VBA编辑器(插入 - >类模块)的新类模块并命名模块ISBN。您还需要在VBA编辑器添加引用微软XML(工具 - >参考)
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)
您可以测试它的工作原理与下面的code段正常的VBA模块中:
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
然后只需键入testlookup进入即时窗口(查看 - >立即窗口)。你应该看到的响应:
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可以返回比我在上面的类收集数据越多,在这里阅读API参考:的http:/ /isbndb.com/docs/api/ 以及定制类您的需求。
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.
我发现这篇文章在解释如何使用XMLHTTP来自内部的访问非常有帮助:
http://www.15seconds.com/issue/991125.htm
I found this article very helpful in explaining how to use xmlhttp from within access: http://www.15seconds.com/issue/991125.htm
这是XML DOM方法和XMLHtt prequest对象MSDN的页面也很有用(因为我是一个新用户,我只能上传两个活动链接,你就必须更换点在下面的网址):
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 COM / EN-US /库/ ms757828(V = VS.85)的.aspx
msdn microsoft com/en-us/library/ms757828(v=VS.85).aspx
微软MSDN COM / EN-US /库/ ms535874(V = vs.85)的.aspx
msdn microsoft com/en-us/library/ms535874(v=vs.85).aspx
这篇关于ISBN - > bookdata查找填写数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!