# Build a web scraper by Making a request to “theyfightcrime.org”
# Extract the two characters generated by the website from the HTML and
# Save the male characters in files 50 times

# Synopsis
# The webscrapper makes calls to the web by using the requests library
# Docs : http://docs.python-requests.org/en/master/user/quickstart/#raw-response-content

# get requests library
import requests
import re

textRegex = re.compile('<P>(.+?)</P>')

# Open 2 files
f = open("female.txt", "w")
m = open ("male.txt", "w")

# make rest calls to theyfightcrime.org,
# Write a HTML Parser that extracts the first and second line of the message in HTML
def getWebString():
    r = requests.get('https://theyfightcrime.org')
    m2 = textRegex.findall(r.text)
    splitstrs = m2[0].split('.')
    return splitstrs

def getLineFromWeb():
    strs = getWebString()
    print(strs)
    print(len(strs))
    if(len(strs) != 3):
        strs = getWebString()
    m.write(strs[0]+'\n')
    f.write(strs[1]+'\n')

# Save the data into different files
def getAllData():
    for x in range(1,51):
        print(" Getting Strings "+ str(x) )
        getLineFromWeb()


getAllData()






