Using BeautifulSoup to search html for string

后端 未结 4 1294
予麋鹿
予麋鹿 2020-11-30 01:20

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<

4条回答
  •  广开言路
    2020-11-30 01:30

    In addition to the accepted answer. You can use a lambda instead of regex:

    from bs4 import BeautifulSoup
    
    html = """

    test python

    """ soup = BeautifulSoup(html, "html.parser") print(soup(text="python")) print(soup(text=lambda t: "python" in t))

    Output:

    []
    ['test python']
    

提交回复
热议问题