Final Project: Markov Rap Bot using Example's "Change The Way You Kiss Me"


#1



Would've loved if I could get the result to remove the [], commas and apostrophes. Other than that works just how I wanted to more or less.

Always looking to improve. Let me know how I can :slight_smile:

from markov_python.cc_markov import MarkovChain
import urllib2
import re
import bs4 as bs

exampleRapperUrl = "http://www.metrolyrics.com/change-the-way-you-kiss-me-lyrics-example.html"
links = urllib2.urlopen(exampleRapperUrl)
data = links.read()

soup = bs.BeautifulSoup(data, "html.parser")
tagged_values = soup.find("div", {"class": "lyrics-body"})
tagged_values = tagged_values.text
tagged_values = str(tagged_values)

charsToRemove = ['<br>', "<p>", "<div>", '</br>', "</p>", "</div>", "<p"]
for char in charsToRemove:
    tagged_values = tagged_values.replace(char, "")

mc = MarkovChain()
mc.add_string(tagged_values)

hi = mc.generate_text(20)

print hi


#2

Hi, @colinwarn ,

Does it help if you use this to display the output? ...

print(" ".join(hi))

I modified and ran your code in Python 3 ...

from cc_markov import MarkovChain
import urllib
import re
import bs4 as bs

exampleRapperUrl = "http://www.metrolyrics.com/change-the-way-you-kiss-me-lyrics-example.html"
links = urllib.request.urlopen(exampleRapperUrl)
data = links.read()

soup = bs.BeautifulSoup(data, "html.parser")
tagged_values = soup.find("div", {"class": "lyrics-body"})
tagged_values = tagged_values.text
tagged_values = str(tagged_values)

charsToRemove = ['<br>', "<p>", "<div>", '</br>', "</p>", "</div>", "<p"]
for char in charsToRemove:
    tagged_values = tagged_values.replace(char, "")

mc = MarkovChain()
mc.add_string(tagged_values)

hi = mc.generate_text(100)

print(" ".join(hi))

Output:

kiss me 'cause you changed the way you kiss me 'cause you changed the way you kiss meour love feels wrong cant hide the cracks i guarantee you'll miss me i know you're gonna miss me 'cause you changed the way you kiss me i know you're gonna miss me 'cause you changed the way you kiss mewe used to be so so soulful al green on the next high we get by with a so called soul mate made for each other chit chat but that dried up wise up to the cutting edge facts now i'm chilling on