[Python] Using BeautifulSoup to search HTML for string

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am using BeautifulSoup to look for user-entered strings on a specific page. For example, I want to see if the string 'Python' is located on the page: http://python.org

    When I used: find_string = soup.body.findAll(text='Python'), find_string returned []

    But when I used: find_string = soup.body.findAll(text=re.compile('Python'), limit=1), find_string returned [u'Python Jobs'] as expected

    What is the difference between these two statements that makes the second statement work when there are more than one instances of the word to be searched?

    Continue reading...

Compartilhe esta Página