---
title: "利用图书的ISBN从豆瓣网获取图书的信息 ."
author: "feohoo"
date: "2012-08-28T14:49:09Z"
tags: []
categories: ["互联网"]
slug: "isbn"
draft: false
lastmod: "2012-08-28T14:49:09Z"
id: 1665148
url: "https://feohoo.iteye.com/blog/1665148"
---

当我们获取了图书的条码后,可以使用WebResponse 和HttpWebRequest从豆瓣网获取图书的信息.获取图书信息的地址:

"[http://api.douban.com/book/subject/isbn/](http://api.douban.com/book/subject/isbn/)   加上图书的条码,可以是只有数字,也可以在中间加入"-"(不包括引号)如:978-7-115-18103-9.

注意,返回的数据需要使用UTF-8编码,如果使用GB2312,将会是乱码.

将下面的函数加入工程,在适当的地方调用,传入ISBN号,即可获取图书相关的信息.

        public string   GetBookInfo(string ISBN)  
        {  
            string url = "[http://api.douban.com/book/subject/isbn/](http://api.douban.com/book/subject/isbn/)";  
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url + ISBN);  
            WebResponse response = request.GetResponse();  
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));  
            string BookInfo = reader.ReadToEnd();  
            reader.Close();  
            reader.Dispose();  
            response.Close();  
            return BookInfo;

        }

在没有申请豆瓣网的APIKEY时,每分钟只能调用10次,如果申请了可以达到40次.

若要包含APIKEY,则在访问时的URL改为:

[http://api.douban.com/book/subject/isbn/ISBN?APIKEY](http://api.douban.com/book/subject/isbn/ISBN?APIKEY)=你的APIKEY   ,其中的ISBN即书号,最后你的APIKEY需要替换成你的号码.

 

 

查询例子：

[http://api.douban.com/book/subject/isbn/978-7-115-18103-9](http://api.douban.com/book/subject/isbn/978-7-115-18103-9)

 

**查询出来的结果：** 

 &lt;?xml version="1.0" encoding="UTF-8" ?&gt;

[**-**](/admin/blogs/) &lt;entry xmlns="**http://www.w3.org/2005/Atom**" xmlns:db="**http://www.douban.com/xmlns/**" xmlns:gd="**http://schemas.google.com/g/2005**" xmlns:openSearch="**http://a9.com/-/spec/opensearchrss/1.0/**" xmlns:opensearch="**http://a9.com/-/spec/opensearchrss/1.0/**"&gt;

  &lt;id&gt;**http://api.douban.com/book/subject/3171438**&lt;/id&gt;

  &lt;title&gt;**数控加工与编程**&lt;/title&gt;

  &lt;category scheme="**http://www.douban.com/2007#kind**" term="**http://www.douban.com/2007#book**" /&gt;

[**-**](/admin/blogs/) &lt;author&gt;

  &lt;name&gt;**顾晔 编**&lt;/name&gt;

  &lt;/author&gt;

  &lt;link href="**http://api.douban.com/book/subject/3171438**" rel="**self**" /&gt;

  &lt;link href="**http://book.douban.com/subject/3171438/**" rel="**alternate**" /&gt;

  &lt;link href="**http://img1.douban.com/spic/s5924224.jpg**" rel="**image**" /&gt;

  &lt;link href="**http://m.douban.com/book/subject/3171438/**" rel="**mobile**" /&gt;

  &lt;summary&gt;**《高职高专机电类规划教材•数控加工与编程》以Fanuc 0i系统为蓝本，深入浅出地讲述了数控车床、加工中心的基本理论知识及其编程方法。书中所有程序中的每行语句后都附有详细、清晰的注释说明，所有程序都在数控机床上实际运行过。《高职高专机电类规划教材•数控加工与编程》各章设有思考与练习，便于学生更好地掌握所学内容，并附有Fanuc 0i系统、华中数控系统常用指令表及说明，供读者查阅和学习。**&lt;/summary&gt;

  &lt;db:attribute name="**isbn10**"&gt;**7115181039**&lt;/db:attribute&gt;

  &lt;db:attribute name="**isbn13**"&gt;**9787115181039**&lt;/db:attribute&gt;

  &lt;db:attribute name="**title**"&gt;**数控加工与编程**&lt;/db:attribute&gt;

  &lt;db:attribute name="**pages**"&gt;**213**&lt;/db:attribute&gt;

  &lt;db:attribute name="**author**"&gt;**顾晔 编**&lt;/db:attribute&gt;

  &lt;db:attribute name="**price**"&gt;**24.00元**&lt;/db:attribute&gt;

  &lt;db:attribute name="**pubdate**"&gt;**2008-9**&lt;/db:attribute&gt;

  &lt;gd:rating average="**0**" max="**10**" min="**0**" numRaters="**0**" /&gt;

  &lt;/entry&gt;

中图法目录查询：

[http://ztflh.jourserv.com/](http://ztflh.jourserv.com/)

- A MAKESI[主义、LIENING主义、MAOZEDONG思想、DENGXIAOPING理论](http://ztflh.jourserv.com/html/2.html)
- B[哲学、宗教](http://ztflh.jourserv.com/html/141.html)
- C[社会科学总论](http://ztflh.jourserv.com/html/896.html)
- D[政治、法律](http://ztflh.jourserv.com/html/1110.html)
- E[军事](http://ztflh.jourserv.com/html/2235.html)
- F[经济](http://ztflh.jourserv.com/html/2666.html)
- G[文化、科学、教育、体育](http://ztflh.jourserv.com/html/4237.html)
- H[语言、文字](http://ztflh.jourserv.com/html/5668.html)
- I[文学](http://ztflh.jourserv.com/html/6191.html)
- J[艺术](http://ztflh.jourserv.com/html/6495.html)
- K[历史、地理](http://ztflh.jourserv.com/html/7464.html)
- N[自然科学总论](http://ztflh.jourserv.com/html/9484.html)
- O[数理科学和化学](http://ztflh.jourserv.com/html/9580.html)
- P[天文学、地球科学](http://ztflh.jourserv.com/html/11634.html)
- Q[生物科学](http://ztflh.jourserv.com/html/13945.html)
- R[医药、卫生](http://ztflh.jourserv.com/html/17417.html)
- S[农业科学](http://ztflh.jourserv.com/html/21152.html)
- T[工业技术](http://ztflh.jourserv.com/html/25844.html)
- U[交通运输](http://ztflh.jourserv.com/html/40585.html)
- V[航空、航天](http://ztflh.jourserv.com/html/44097.html)
- X[环境科学、安全科学](http://ztflh.jourserv.com/html/45419.html)
- Z[综合性图书](http://ztflh.jourserv.com/html/45735.html)