BeautifulSoup 에세이

1195 단어

Learn BeautifulSoup


BeautifulSoup 사용법


최경재

기본 문법 및 용법


초기화


soup = BeautifulSoup(html, 'lxml') (or BeautifelSoup(open(filename), 'lxml') )

4대 객체 종류

* Tag
    *    soup.[title| head| a| p|  ]
    * name: soup.name, soup.head.name
    * attrs 
* NavigableString
    * soup.p.string 
* BeatifulSoup
* Commit

두루

*   .contents .children
*   .descendants
*   .parent .parents
*   .next_sibling .privious_sibling
*   .string
*   .string .stripped_strings

문서 트리 검색

* find_all(name, attrs, recursive, text, **kwargs)
    * name:  name 
        *  
        *  
        *  
        * True
        *  
    * kwargs: 。。。
    * text:  
    * limit :  
    * recursive:  
*   find find_parent, find_all_next 

CSS 선택기

> select 

4
  • 태그 기반 soup.select('title')

  • 4
  • 클래스 이름 soup.select('.content')

  • 4
  • id soup을 통해select('#link1')

  • 4
  • 속성 찾기 soup.select('div [class="content"]')
  • 좋은 웹페이지 즐겨찾기