I need help with my python final project(my markov_chain isn't working)


#1

This is my fetch.py
from urllib2 import urlopen
from bs4 import BeautifulSoup
import unicodedata
import ast
import requests
import re

html = requests.get("http://www.winespectator.com/dailypicks/category/catid/1/page/").content
wineReviews = BeautifulSoup(html)
lines = []
for page in xrange(1, 10):
for headLine in wineReviews.find_all("div", { "class" : "paragraph" }):
txt1 = headLine.get_text()
txt1 = re.sub('[ \t]+', ' ', txt1).strip()
lines.append(txt1)
with open("/Users/mobpro/desktop/markov_chain/winereviews.txt", "w") as f:
f.write(u'\n\n'.join(lines).encode('utf-8'))

AND this is my run.py

from markov_python.cc_markov import MarkovChain

mc = MarkovChain()
mc.add_file('/Users/liamchae/Documents/markov_chain/wineReviews.txt')

mc.add_string("red")

print mc.generate_text(10)