ISBN - > bookdata查找填写数据库
-
20-09-2019 - |
题
好,我想数据库小型图书馆。
我只有与数据库经验有限,并没有从网络服务器查询。
我将要检索像标题信息,发布者,也许作者,描述 我能想到dooing这个最简单的方式是通过ISBN查找它们。
我遇到isbndb.com之前,但访问它的API似乎相当复杂的。
我不知道我应该如何去这样做。
解决方案
最近,我不得不这样做正是这一点,因为我们索引我们的图书馆为保险起见。下面是VBA I类黑客攻击一起的代码:
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密钥,粘贴上述代码(与您的钥匙)插入在VBA编辑器(插入 - >类模块)一个新的类模块并命名模块“ISBN”。您还需要在VBA编辑器添加引用“微软XML”(工具 - >参考)
可以测试它的工作原理与代码段低于正常VBA模块中:
Public Function testlookup()
Dim book
Set book = New isbn
book.Lookup ("0007102968")
Debug.Print book.Title
Debug.Print book.PublisherText
End Function
然后,只需输入“testlookup”到即时窗口(查看 - >立即窗口)。应该可以看到的响应:
The Times book of quotations
[Glasgow] : Times Books : 2000.
isbnDB可以返回比我在上述类收集数据更多,这里读出的API参考: HTTP:/ /isbndb.com/docs/api/ 和定制类您的需求。
我发现这篇文章中解释了如何使用XMLHTTP从访问中非常有帮助: http://www.15seconds.com/issue/991125.htm
在XML DOM方法和XMLHttpRequest对象的MSDN页面也很有用(因为我是一个新用户,我只能上传两个活动链接,你就必须更换点在下面的网址):
MSDN的Microsoft COM / EN-US /库/ ms757828(V = VS.85)的.aspx
MSDN的Microsoft COM / EN-US /库/ ms535874(V = vs.85)的.aspx
其他提示
这是一个不完整的答案,但它应该让你开始(我没有使用XML数据作为工作的回报)。
此代码具有基础:
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
从网页的响应是在XMLHTTP对象的.responseText属性。你怎么处理是超越我。我知道的是,访问新闻组大师之一已出版了从Access使用Web服务的教程,但我不能找到它。这篇文章可能有一些做的问题:
在ISBNdb.com API看起来简单。下面的请求应该找回你想要的信息...只是代替您访问密钥“YourKey”和书号为“YourISBN”。
https://isbndb.com/api/books.xml?access_key=YourKey&results=texts&index1=isbn&value1=YourISBN
在响应是XML其中包含有关一本书,其ISBN您提交的信息。
您可以从美国国会图书馆使用MARC21 XML。
我做同样的事情,你,建立一个数据库,以容纳我的图书馆。扫描的ISBN从这个URL收集数据 http://z3950.loc.gov:7090/voyager?版本= 1.1&操作= searchRetrieve&查询= YOUR_ISBN&maximumRecords = 1
响应数据然后填充在与所有的数据的形式。你并不需要一个帐户,只是URL。
在回应进来(如前所述)XML,你可以从那里使用任何你想要的语言解析(我的选择恰好是PHP)。
什么是您使用的语言?你需要一个程序/脚本来呈现一个表单,您可以输入ISBN,然后将得到isbndb.com数据并填充数据库。我用的API了一点,但有一段时间,这是非常简单的。