天天看點

Beautiful Soup 中文文檔

原文位址:

https://www.crummy.com/software/BeautifulSoup/bs3/documentation.zh.html

原文 by Leonard Richardson ([email protected]) 

翻譯 by Richie Yan ([email protected]) 

###如果有些翻譯的不準确或者難以了解,直接看例子吧。### 

Beautiful Soup 是用Python寫的一個HTML/XML的解析器,它可以很好的處理不規範标記并生成剖析樹(parse tree)。 它提供簡單又常用的導航(navigating),搜尋以及修改剖析樹的操作。它可以大大節省你的程式設計時間。 對于Ruby,使用Rubyful Soup。

  • Navigating 剖析樹
    • parent

    • contents

    • string

    • nextSibling

       and 

      previousSibling

    • next

       and 

      previous

    • 周遊

      Tag

    • 使用标簽名作為成員
  • Searching 剖析樹
    • The basic find method: 

      findAll(name, attrs, recursive, text, limit, **kwargs)

      • 使用CSS類查找
      • 像 

        findall

        一樣調用tag
    • find(name, attrs, recursive, text, **kwargs)

    • first

      哪裡去了?
  • Searching 剖析樹内部
    • findNextSiblings(name, attrs, text, limit, **kwargs)

       and 

      findNextSibling(name, attrs, text, **kwargs)

    • findPreviousSiblings(name, attrs, text, limit, **kwargs)

       and 

      findPreviousSibling(name, attrs, text, **kwargs)

    • findAllNext(name, attrs, text, limit, **kwargs)

       and 

      findNext(name, attrs, text, **kwargs)

    • findAllPrevious(name, attrs, text, limit, **kwargs)

       and 

      findPrevious(name, attrs, text, **kwargs)