How to find spans with a specific class containing specific text using beautiful soup and re?

前端 未结 3 1686
無奈伤痛
無奈伤痛 2021-02-01 07:16

how can I find all span\'s with a class of \'blue\' that contain text in the format:

04/18/13 7:29pm

which could therefore be:

3条回答
  •  天涯浪人
    2021-02-01 07:46

    This pattern seems to satisfy what you're looking for:

    >>> pattern = re.compile('.*?(\d\d/\d\d/\d\d \d\d?:\d\d\w\w)')
    >>> pattern.match('here is a lot of text that i dont need')
    >>> pattern.match('this is the span i need because it contains 04/18/13 7:29pm').groups()
    ('04/18/13 7:29pm',)
    

提交回复
热议问题