[Python] BeautifulSoup note

  • BeautifulSoup(html, fromEncoding='...', smartQuotesTo='html')
    • fromEncoding: 用在非UTF-8編碼的網頁。有些網頁像Getchu的網頁有時候也會有問題,這不是BeautifulSoup本身的問題,只是網站標示的編碼跟實際上 使用的編碼不同。保險的作法是用iconv轉成utf-8再丟給BeautifulSoup處理。
    • smartQuotesTo='html': HTML/XML Entity轉換
  • .find(text='abc')
    HTML: <a href='..'>hello</a> ex: soup.find('a', text='hello') ==> hello #只會傳回標籤內的文字,不會傳回Tag物件

沒有留言:

張貼留言