抓取豆瓣书影音信息

豆瓣的书影音档案比较有意思,在hexo插件里发现了一个工具可以很方便的获取并生成网页。

项目地址:mythsman/idouban
mythsman/hexo-douban

idouban

这是一个在网页中嵌入个人豆瓣页面的 javascript 插件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<body>
<div id="douban"></div>
</body>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/idouban/dist/index.css"
/>
<script
src="https://cdn.jsdelivr.net/npm/idouban/dist/index.js"
onload="idouban.init({
selector:'#douban',
lang: 'zh',
douban_id: '162448367',
type: 'book',
quote: 'This is my books',
actions: ['do','wish','collect'],
page_size: 10,
max_line: 4
})"
></script>

只要用真实的id替换,就可以生成书影音信息网页。

hexo-douban

这是一个hexo插件,简单设置就可以。

  • 安装插件
    $ npm install hexo-douban --save
  • _config.yml中加入以下内容(站点配置文件,不是主题配置文件)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    douban:
    id: 162448367
    builtin: false
    dynamic: false
    item_per_page: 10
    meta_max_line: 4
    customize_layout: page
    swup: false
    book:
    path: books/index.html
    title: "This is my book title"
    quote: "This is my book quote"
    actions:
    - do
    - wish
    - collect
    option:
    movie:
    path: movies/index.html
    title: "This is my movie title"
    quote: "This is my movie quote"
    actions:
    - do
    - wish
    - collect
    option:
    game:
    path: games/index.html
    title: "This is my game title"
    quote: "This is my game quote"
    actions:
    - do
    - wish
    - collect
    option:
    song:
    path: songs/index.html
    title: "This is my song title"
    quote: "This is my song quote"
    actions:
    - do
    - wish
    - collect
    option:
    book,movie,game,song中不要的可删掉。
    do,wish,collect顺序可换,分别是在看,想看,已看的意思,默认打开第一个。
  • 注意事项
    安装douban插件后,不能用hexo d了,因为hexo douban跟hexo deploy 的前缀都是hexo d。
    hexo g -d是可以用的。
    第一次使用 hexo douban 时,后台会异步进行数据获取,一般需要等待一段时间(后台访问你的标记页面)才能查到数据。
  • 显示
    打开/books,/movies,/games,/songs就看到相应的网页。
  • 在主题配置文件 _config.yml加菜单项
    1
    2
    3
    4
    5
    6
    7
    menu:
    Home: /
    Archives: /archives
    Books: /books #This is your books page
    Movies: /movies #This is your movies page
    Games: /games #This is your games page
    Songs: /songs #This is your songs page