豆瓣 API :http://www.douban.com/service/apidoc/

豆类 API 参考手册:http://www.douban.com/service/apidoc/reference/subject\#获取书籍新闻

豆子 API 火速入门:http://www.douban.com/service/apidoc/guide

 

鉴于要拿走图书的音信,所以先建个图书的类吧:

1   namespace doubantest
2   {
3       class bookinfo
4       {
5           private string _name;
6           private string _author;
7           private string _imageurl;
8           private string _summary;
9           private string _isbn;
10          private string _pages;
11          private string _price;
12          private string _publisher;
13          private string _pubdate;
14 
15          public bookinfo()
16          {
17              this._name = string.Empty;
18              this._author = string.Empty;
19              this._imageurl = string.Empty;
20              this._summary = string.Empty;
21              this._isbn = string.Empty;
22              this._pages = string.Empty;
23              this._price = string.Empty;
24              this._publisher = string.Empty;
25              this._pubdate = string.Empty;
26          }
27 
28          public string Name
29          {
30              get {
31                  return this._name;
32              }
33              set {
34                  this._name = value;
35              }
36          }
37 
38          public string Author
39          {
40              get
41              {
42                  return this._author;
43              }
44              set
45              {
46                  this._author = value;
47              }
48          }
49 
50          public string Imageurl
51          {
52              get
53              {
54                  return this._imageurl;
55              }
56              set
57              {
58                  this._imageurl = value;
59              }
60          }
61 
62          public string Summary
63          {
64              get
65              {
66                  return this._summary;
67              }
68              set
69              {
70                  this._summary = value;
71              }
72          }
73 
74          public string Isbn
75          {
76              get
77              {
78                  return this._isbn;
79              }
80              set
81              {
82                  this._isbn = value;
83              }
84          }
85 
86          public string Pages
87          {
88              get
89              {
90                  return this._pages;
91              }
92              set
93              {
94                  this._pages = value;
95              }
96          }
97 
98          public string Price
99          {
100             get
101             {
102                 return this._price;
103             }
104             set
105             {
106                 this._price = value;
107             }
108         }
109
110         public string Publisher
111         {
112             get
113             {
114                 return this._publisher;
115             }
116             set
117             {
118                 this._publisher = value;
119             }
120         }
121
122         public string Pubdate
123         {
124             get
125             {
126                 return this._pubdate;
127             }
128             set
129             {
130                 this._pubdate = value;
131             }
132         }
133
134     }
135 }

 

先添加using

1 using System.Net;
2 using System.IO;
3 using System.Xml;

 

下一场正是经过API获取数据了,遵照豆瓣提供的格式向服务器获取数据:

1  HttpWebRequest myRequest = null;
2  HttpWebResponse myHttpResponse = null;
3  string doubanurl = “http://api.douban.com/book/subject/isbn/“;
4  string geturl = doubanurl + textBoxisbnisbn.Text.ToString().Trim();
5  myRequest = (HttpWebRequest)WebRequest.Create(geturl);
6  myHttpResponse = (HttpWebResponse)myRequest.GetResponse();
7  StreamReader reader = new StreamReader(myHttpResponse.GetResponseStream());
8  string xmldetail = reader.ReadToEnd();
9  reader.Close();
10 myHttpResponse.Close();

 

数量得到完毕(若是输入正确的话),得到的是xml格式,内容如下:

1    <?xml
version=”1.0″
encoding=”UTF-8″ ?> 
2  – <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;
3    <id>http://api.douban.com/book/subject/4744120&lt;/id&gt
四    <title>FLUENT流体分析及假冒伪造低劣实用教程(附光盘)</title> 
5    <category
scheme=”http://www.douban.com/2007\#kind
term=”http://www.douban.com/2007\#book” /> 
6  – <author>
7    <name>朱红钧</name> 
8    </author>
9    <link
href=”http://api.douban.com/book/subject/4744120
rel=”self” /> 
10   <link
href=”http://book.douban.com/subject/4744120/
rel=”alternate” /> 
11   <link
href=”http://img3.douban.com/pics/book-default-small.gif
rel=”image” /> 
1二   <summary>FLUENT是CFD软件中相对成熟和应用最为常见的商业软件。本书以FLUENT 陆.叁.贰陆版本为原本,由浅入深、循途守辙地介绍了选用FLUENT实行流体分析与虚假的各部分文化,包涵前处理网格生成、湍流模型、传热分析、非定常流动难题、多相流模型、转动模型、组分输运与化学反应模型、流动分析后处理、UDF使用及编辑等。全书通过基础知识和实例介绍相结合的方法讲解了从数值建立模型到总结后甩卖各部分操作的骨干措施和手续,最终以综合实例的办法尤其向读者介绍了超群众工作程难点的流体分析及假冒伪造低劣艺术。  本书可视作水利工程、土木、石工、储存运输、航空、财富、环境、机械、建筑、中国人民解放军海军事工业程高校、材质、引力、冶金等正规的博士和本科生的持筹握算流体力学教材,同时也可看做CFD相关领域专业技术人士的参阅用书。</summary> 
13   <db:attribute name=”isbn10″>7115225265</db:attribute> 
14   <db:attribute name=”isbn13″>9787115225269</db:attribute> 
15   <db:attribute name=”title”>FLUENT流体分析及假冒伪造低劣实用教程(附光盘)</db:attribute> 
16   <db:attribute name=”pages”>388</db:attribute> 
17   <db:attribute name=”author”>朱红钧</db:attribute> 
18   <db:attribute name=”price”>58.0</db:attribute> 
19   <db:attribute name=”publisher”>人民邮政和电信出版社</db:attribute> 
20   <db:attribute name=”binding”>平装</db:attribute> 
21   <db:attribute name=”pubdate”>2010-4-1</db:attribute> 
22   <gd:rating
average=”0″
max=”10″
min=”0″
numRaters=”0″ /> 
23   </entry>

 

上边正是从XML里得到要求的数目:

1                  books = new bookinfo();

3                  XmlDocument xml = new XmlDocument();
4                  xml.LoadXml(xmldetail);
5                  XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
6                  nsmgr.AddNamespace(“db”, “http://www.w3.org/2005/Atom“);
7                  XmlElement root = xml.DocumentElement;
8                  XmlNodeList nodes = root.SelectNodes(“/db:entry”, nsmgr);

10                 foreach (XmlNode nodeData in nodes)
11                 {
12                     foreach (XmlNode childnode in nodeData.ChildNodes)
13                     {
14                         string str = childnode.Name;
15                         switch (str)
16                         {
17                             case “title”:
18                                 books.Name = childnode.InnerText;
19                                 break;
20                             case “link”:
21                                 if (childnode.Attributes[1].Value == “image”)
22                                 {
23                                     books.Imageurl = childnode.Attributes[0].Value;
24                                 }
25                                 break;
26                             case “summary”:
27                                 books.Summary = childnode.InnerText;
28                                 break;
29                             case “db:attribute”:
30                                 {
31                                     switch (childnode.Attributes[0].Value)
32                                     {
33                                         case “isbn13”:
34                                             books.Isbn = childnode.InnerText;
35                                             break;
36                                         case”pages”:
37                                             books.Pages = childnode.InnerText;
38                                             break;
39                                         case “author”:
40                                             books.Author = childnode.InnerText;
41                                             break;
42                                         case “price”:
43                                             books.Price = childnode.InnerText;
44                                             break;
45                                         case “publisher”:
46                                             books.Publisher = childnode.InnerText;
47                                             break;
48                                         case “pubdate”:
49                                             books.Pubdate = childnode.InnerText;
50                                             break;
51                                     }//end switch
52                                     break;
53                                 }
54                         }//end switch
55                     }//end foreach
56                 }//end foreach
57
58                 labeltitle.Text = books.Name;
59                 labelauthor.Text = books.Author;
60                 labelimageurl.Text = books.Imageurl;
61                 labelisbn.Text = books.Isbn;
62                 labelpage.Text = books.Pages;
63                 labelprice.Text = books.Price;
64                 labelpublisher.Text = books.Publisher;
65                 labelpubdate.Text = books.Pubdate;
66                 labelsummary.Text = books.Summary;

 

最后看眼大概效果:

图片 1

 

实质上标准的api的UTiggoL应该是:

1 http://api.douban.com/book/subject/isbn/%7BisbnID%7D?apikey=%7Byourkeyapi}

 

apikey是友好报名的

不过apikey其实未有也得以用

印象中貌似有apikey的话,没分钟允许连接三十7次

从未有过的话只可以二十二遍

抢先的话会被封IP…

 

虽然叫C#选择豆瓣API,其实豆瓣API首如果post和get操作,然和语言都能选取的

近年来准备做个pivot的书籍检索,所以必要从网上爬点东西,豆瓣那上边东西挺全的,而且有API,就先从豆瓣下了

至于API,详细的看豆瓣的牵线吧:

相关文章

网站地图xml地图