Hello World
Spiga

使用calibre抓取2013年的MSDN Magazine

2013-06-18 23:11 by 老赵, 9446 visits

前段时间入手Kindle Paperwhite,这已经是我第三个Kindle设备了。想当年我花了四五千块钱,在亚马逊美国站上跟着老美预定,可谓是全世界第一批Kindle DX(大屏幕的那款阅读器)用户,不过用着用着后来还是去玩平板了。这次Kindle Paperwhite出了国行设备,才849元,顿觉实在是太便宜了,立即下单,第二天就拿到了这台设备。

有了设备自然要用,除了官方书店里买的书以外,第三方的内容自然也必不可少,毕竟目前国内的Kindle电子书还太少(尤其是计算机方面的),还好之前也从国外买了不少mobi电子书,可以直接看。更重要的是,我发现可以使用calibre这个电子书管理神器来抓取网络上的内容,生成一本电子期刊,甚至可以利用亚马逊提供的邮箱推送服务来传送到Kindle设备上。

calibre可以通过一个RSS链接经过简单设置转化为电子书,是为“基本模式”,与此相对的“高级模式”便是自己编写Python脚本来抓取内容了,这样的抓取脚本被称为“recipe”。calibre为此提供了一个抓取框架,让我们覆盖一些方法,提供一些基本信息,就会去自动下载网页内容了。其实calibre也已经内置许多新闻源的抓取脚本了,但自带的MSDN Magazine脚本只能通过RSS来获取最新的内容,而我的目标是将某个月的内容抓取成一本书,要实现这一点只能自己动手丰衣足食了。

本来我还想看看是否能够使用一个脚本来抓取历史上所有的内容,结果发现这个基本很难。我猜MSDN Magazine的编辑们也是一群不懂技术的人,甚至是交给第三方公司在维护,用了一款很土鳖的CMS系统,生成的HTML格式很差。还好,每一年的版式似乎还是相同的,那我至少可以用同一份脚本来抓取2013年里每个月的内容。尽管如此,要获取所有文章的栏目,标题以及简介还是一份挺麻烦的工作,因为HTML使用地不规则好么!

至于calibre抓取框架本身,要说复杂倒也还好,只不过文档实在讲的有些不清不楚,又难以调试,所以开发起来只得不断尝试,效率很低。这个框架用到了Beautiful Soup,但我根据它的文档却发现好多地方不太一样,后来才发现calibre集成的是其旧版。更坑爹的是,根据Beautiful Soup文档中的包引入方式:

from BeautifulSoup import BeautifulSoup, NavigableString

这么做不会出错,也能正确调用其API,但却无法与框架中的soup对象配合使用,例如使用isinstance来判断其中的文本节点是否是NavigableString类型的对象,居然会返回False!后来才发现,原来在calibre中需要这么做才行:

from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString

发现了没?框架中使用的是calibre.ebooks.BeautifulSoup包,而不是BeautifulSoup。既然如此,那为什么还要让它引入成功?为什么我将一个BeautifulSoup节点添加到框架的DOM树中时,既没有报错也不生效?总之,这些坑浪费了我许多时间,真是岂有此理。

2013年MSDN Magazine的抓取脚本我已经上传到了GitHub上,欢迎随意使用。最近我还打算写几个脚本用来抓取其他一些内容,例如每日的InfoQ新闻等等。InfoQ的RSS只输出摘要,令人不爽,但这对于calibre来说完全不成问题——反正内容是去网页上抓下来的。

Creative Commons License

本文基于署名 2.5 中国大陆许可协议发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名赵劼(包含链接),具体操作方式可参考此处。如您有任何疑问或者授权方面的协商,请给我留言

Add your comment

23 条回复

  1. Guang
    218.30.179.*
    链接

    Guang 2013-06-19 09:19:35

    两个多月了才发新文, 老赵最近产量下降啊...

  2. 链接

    Xin Lu 2013-06-19 09:52:58

    自从发现GoogleReader推送到kindle上内容里,infoq只有摘要,就把infoq退订了。 我用的第三方的GR推送服务http://www.klip.me/googlereader/,还不错,可惜马上就不能用了

  3. 老赵
    admin
    链接

    老赵 2013-06-19 10:10:22

    @Guang

    懒……还有就是没有心情,哈哈哈……

  4. 老赵
    admin
    链接

    老赵 2013-06-19 10:10:33

    @Xin Lu

    不喜欢机械的推送呢……

  5. bystander
    119.97.214.*
    链接

    bystander 2013-06-19 16:39:13

    机械的推荐非常之不靠谱..没有足够个性化..

  6. mcpssx
    59.175.192.*
    链接

    mcpssx 2013-06-25 09:26:41

    老赵渐渐抛弃了微软平台了,从mac到电子书平台,这就是趋势啊

  7. 老赵
    admin
    链接

    老赵 2013-06-25 09:50:28

    @mcpssx

    你真是个脑残啊,说的什么乱七八糟的,都完全不要脸的是么,现在除了骂你都懒得回应你,你每次都来讨骂很开心吧?

  8. zicjin
    114.226.94.*
    链接

    zicjin 2013-06-25 21:09:33

    看了一下,这python代码读页面太坑爹了。 推荐LZ看看这个 http://phantomjs.org 用jquery读多爽。

  9. 老赵
    admin
    链接

    老赵 2013-06-25 22:00:56

    @zicjin

    这又不是我能挑的。

  10. 为了梦想
    218.56.181.*
    链接

    为了梦想 2013-06-26 08:58:32

    kindle读书爽吗?我一直想买个电子阅读器,但不知道什么样的适用

  11. 老赵
    admin
    链接

    老赵 2013-06-26 13:59:47

    @为了梦想

    爽,很爽,非常爽。

  12. rhapsodyn
    121.14.96.*
    链接

    rhapsodyn 2013-06-27 16:39:41

    老赵没刷duokan? 用的原生的系统?

  13. oec2003
    27.17.30.*
    链接

    oec2003 2013-07-01 11:23:28

    Kindle Paperwhite 看pdf效果怎么样?

  14. 老赵
    admin
    链接

    老赵 2013-07-01 21:45:41

    @rhapsodyn

    不爱刷机。

  15. 老赵
    admin
    链接

    老赵 2013-07-01 21:45:54

    @oec2003

    尺寸合适就很舒服。

  16. zoroseo2020
    35.215.184.*
    链接

    zoroseo2020 2021-02-12 16:57:53

    一个人的成熟,并不表现在获得了多少成就上 彩票,而是面对那些厌恶的人和事,不迎合也不抵触 福彩双色球,只淡然一笑对之。当内心可以容纳很多自己不喜欢的事务时 幸运飞艇,就有了气场!!

  17. rencao
    34.92.139.*
    链接

    rencao 2022-07-23 13:36:24

    [url=https://168won.com/view/shishicaisg/sscindex.html]168SG时时彩开奖结果[/url] [url=https://168won.com/view/shishicaixy/sscindex.html]168幸运时时彩游戏技巧[/url] [url=https://168won.com/view/sgAirship/pk10kai.html]168SG 飞艇稳赚技巧[/url]

  18. rencao
    34.92.139.*
    链接

    rencao 2022-07-23 13:37:06

  19. rencao
    34.92.139.*
    链接

    rencao 2022-07-23 13:37:52

  20. kericnnoe
    111.242.194.*
    链接

    kericnnoe 2022-12-21 04:06:19

    線上博弈資訊站的玩家喜歡比較喜歡有根據的下注技巧 線上博弈資訊站的玩家喜歡比較喜歡有根據的下注技巧

  21. Air Jordan
    147.185.242.*
    链接

    Air Jordan 2025-02-12 13:46:59

  22. Jordan 1
    216.126.233.*
    链接

    Jordan 1 2025-03-27 00:23:22

  23. Yeezy Slides
    104.234.236.*
    链接

    Yeezy Slides 2025-04-26 20:39:40

    Love it or hate it, the Yeezy Foam Runner has become a cultural phenomenon. From its polarizing design to its sky-high resale value, this shoe is more than just footwear—it’s a statement. Whether you’re a hypebeast, a sustainability advocate, or just someone who loves comfy kicks, here’s why the Foam Runner deserves your attention (and maybe a spot in your closet).

    1. The Design: “Ugly” Never Looked This Good When Kanye West first dropped the Foam Runner in 2020, critics called it the “weirdest Yeezy ever” 4. But fast-forward to today, and its chunky, alien-esque silhouette has become a streetwear staple. The shoe’s one-piece EVA foam construction features bold cutouts for breathability and a futuristic aesthetic that screams avant-garde 79.

    Why it works:

    Versatility: Pair it with socks for a cozy fall vibe or go barefoot for summer beach days.

    Bold Aesthetics: The organic curves and “biomorphic” design make it stand out in a sea of basic sneakers 4.

    Unisex Appeal: Available in adult, kid, and infant sizes, it’s a family flex 79.

    1. Sustainability Meets Hype Kanye promised eco-friendly innovation, and the Foam Runner delivers. Made with algae-based foam and recycled materials, each pair helps clean lakes by repurposing harmful algae 79. Even the packaging is minimalist to reduce waste.

    But let’s keep it real: While the eco-credentials are impressive, limited drops and insane resale prices (up to 10x retail!) have left fans frustrated 34. Original retail was 75 – 75–80, but scarcity pushed some colorways to $6,000+ in resale markets 34.

    1. Colorways That Keep Us Obsessed The Foam Runner’s ever-expanding palette is a masterclass in hype. Recent drops include:

    “Ochre” & “MX Cream Clay”: Earthy tones perfect for minimalist outfits (August 2 drop, $80) 210.

    “Mineral Blue”: A moody midnight hue for stealthy flexing 5.

    “Onyx”: Sleek all-black for the “dark mode” enthusiasts (released June 2022) 7.

    “MIST”: A misty brown-gray blend that sold out in seconds 9.

    Styling hacks:

    Socks + Sandals 2.0: Throw on colorful crew socks for a retro vibe.

    Techwear Essential: Match it with cargo pants and a puffer vest.

    Beach-Ready: Water-resistant material means you can rock it poolside 7.

    1. The Hype Train Isn’t Slowing Down From Walmart’s $24 knockoffs (shut down after legal battles 1) to Chinese brands like Peak copying the design 3, the Foam Runner’s influence is undeniable. But nothing beats the OG.

    Why it’s worth the hunt:

    Cultural Impact: It redefined “ugly chic” and inspired a wave of (hole-punched shoes) 6.

    Collector’s Item: Early colorways like the “Marbled” edition are grails for sneakerheads 4.

    Final Word: How to Cop Want to avoid resale scams? Stay alert for restocks! New colorways like “MXT Moon Grey” (2023) and future drops are your best shot at scoring retail 6. Set those app notifications, pray to the Yeezus, and remember: in the world of Foam Runners, patience pays.

    TL;DR: The Yeezy Foam Runner is weird, wonderful, and the shoe of the decade. Grab a pair, wear it with confidence, and join the cult.

    Ready to flex? Drop your Foam Runner stories in the comments!

    Yeezy Slides
    Yeezy Official Website
    Jordan 1
    Jordan 12
    Jordan 11
    Yeezy Slides
    NFL Shop
    NFL Store
    Yeezy Slides
    Yeezy 350
    Jordan 4
    Yeezy Supply
    Jordan 4
    Yeezy Website
    Yeezy Slides
    Jordan 12
    Jordan 11
    Jordan 1
    Air Jodan
    NFL Jerseys
    Yeezy Slides
    Yeezy Supply
    Yeezy Store
    Yeezy Slides
    Louis Vuitton Outlet
    Louis Vuitton Outlet
    Yeezy Shoes
    Yeezy Slides
    Yeezy 350
    Yeezy Slides
    Yeezy Adidas
    Yeezy Official Website
    Adidas Yeezy
    Yeezy Supply
    Yeezy Slides
    Yeezy Official
    Yeezy 350
    Yeezy Slides

    Tags:Yeezy Shoes,Yeezy Slides,Jordan 1,Air Jordan,Jordan

发表回复

登录 / 登录并记住我 ,登陆后便可删除或修改已发表的评论 (请注意保留评论内容)

昵称:(必填)

邮箱:(必填,仅用于Gavatar

主页:(可选)

评论内容(大于5个字符):

  1. Your Name yyyy-MM-dd HH:mm:ss

使用Live Messenger联系我