jquery-like HTML parsing in Python?

前端 未结 4 564
梦毁少年i
梦毁少年i 2020-12-04 10:54

Is there any Python library that allows me to parse an HTML document similar to what jQuery does?

i.e. I\'d like to be able to use CSS selectors

4条回答
  •  無奈伤痛
    2020-12-04 11:36

    If you are fluent with BeautifulSoup, you could just add soupselect to your libs.
    Soupselect is a CSS selector extension for BeautifulSoup.

    Usage:

    >>> from BeautifulSoup import BeautifulSoup as Soup
    >>> from soupselect import select
    >>> import urllib
    >>> soup = Soup(urllib.urlopen('http://slashdot.org/'))
    >>> select(soup, 'div.title h3')
    [

    Science:

    ,

    Star Trek

    , ..]

提交回复
热议问题