How Do You Get Python to Parse Web Pages to Find a String?

Problem scenario
You know a string is buried in a series of web pages. How do you get Python to read the web pages and find the string?

Change the URLs as you desire. Change the "searchterm" variable assignment to the word of your choice. Then run this Python 3 program:

import re
import requests
listofurls = ['', '', '', '', '']

searchterm = "learned"

def finder(yoururl, searchterm):
    r = requests.get(yoururl)
    found =, r.text)
    if found:
      print("The string/pattern '" + searchterm + "' was found when searching " + yoururl)
      print("The string/pattern '" + searchterm + "' was not found when searching " + yoururl)

for x in listofurls:
  finder(x, searchterm)

Leave a comment

Your email address will not be published. Required fields are marked *