Using BeautifulSoup to find a HTML tag that contains certain text

前端 未结 3 1511
情歌与酒
情歌与酒 2020-11-28 08:12

I\'m trying to get the elements in an HTML doc that contain the following pattern of text: #\\S{11}

this is cool #12345678901

<
3条回答
  •  日久生厌
    2020-11-28 09:06

    With bs4 (Beautiful Soup 4), the OP's attempt works exactly like expected:

    from bs4 import BeautifulSoup
    soup = BeautifulSoup("

    this is cool #12345678901

    ") soup('h2',text=re.compile(r' #\S{11}'))

    returns [

    this is cool #12345678901

    ].

提交回复
热议问题