Using BeautifulSoup to search html for string

后端 未结 4 1283
予麋鹿
予麋鹿 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:46

    I have not used BeuatifulSoup but maybe the following can help in some tiny way.

    import re
    import urllib2
    stuff = urllib2.urlopen(your_url_goes_here).read()  # stuff will contain the *entire* page
    
    # Replace the string Python with your desired regex
    results = re.findall('(Python)',stuff)
    
    for i in results:
        print i
    

    I'm not suggesting this is a replacement but maybe you can glean some value in the concept until a direct answer comes along.

提交回复
热议问题