I have a web scraper that I use in a part of a larger program. However, I feel like I semi-repeat my code a lot and take up a lot of room. Is there any way I can condense this code?
def read_mail(mail):
url = [mail] # Ignore this line, please.
i = 0 # Ignore this line, please.
droppedSource = '<td class="item_dropped">(.+?)</td>' # Gets whatever is inbetween the tags
destroyedSource = '<td class="item_destroyed">(.+?)</td>'
totalSource = '<strong class="item_dropped">(.+?)</strong>'
droppedText = re.compile(droppedSource) # Converts regex string into something that can be interpreted by regular library
destroyedText = re.compile(destroyedSource)
totalText = re.compile(totalSource)
html = urllib.urlopen(url[i]).read() # ignore the url[i] part of this line, please.
dropped = re.findall(droppedText,html)
destroyed = re.findall(destroyedText,html)
total = re.findall(totalText,html)
return("Info: " + str(dropped[0])+str(destroyed[0])+str(total[0]))