This commit is contained in:
Ben Harris committed 2018-10-09 02:50:10 -04:00
1 parent a8a5de36f2
commit 58753c7234
38 files changed
+4549 -2523

No files matched your search

+28 -14
View File
@@ -1,25 +1,39 @@
import urllib
#from lxml.html import fromstring
# from lxml.html import fromstring
from bs4 import BeautifulSoup
import random
def getRhymes(word):
words = []
url = 'http://www.rhymer.com/RhymingDictionaryLast/%s.html' % word
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
for t in soup.find_all('table', 'table'):
words.append(random.choice([w for w in t.text.split('\n') if w not in [u'', u'\xa0'] and '-' not in w]))
return words
words = []
url = "http://www.rhymer.com/RhymingDictionaryLast/%s.html" % word
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser")
for t in soup.find_all("table", "table"):
words.append(
random.choice(
[
w
for w in t.text.split("\n")
if w not in [u"", u"\xa0"] and "-" not in w
]
)
)
return words
def rhymeZone(word):
words = []
url = 'http://rhymezone.com/r/rhyme.cgi?Word=%s&typeofrhyme=perfect&org1=syl&org2=l&org3=y' % word
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
url = (
"http://rhymezone.com/r/rhyme.cgi?Word=%s&typeofrhyme=perfect&org1=syl&org2=l&org3=y"
% word
)
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser")
for t in soup.find_all('a', 'd'):
for t in soup.find_all("a", "d"):
w = t.text.rstrip()
if w not in [u'', u'\xa0'] and '?' not in t:
words.append(w.encode('ascii', 'ignore'))
if w not in [u"", u"\xa0"] and "?" not in t:
words.append(w.encode("ascii", "ignore"))
random.shuffle(words)
return words[0:5]