diff --git a/pyquotes/brainyquote/brainyquote.py b/pyquotes/brainyquote/brainyquote.py index 4ad5698..a7cb989 100644 --- a/pyquotes/brainyquote/brainyquote.py +++ b/pyquotes/brainyquote/brainyquote.py @@ -37,24 +37,23 @@ def get_quotes(person, category): URL = "https://www.brainyquote.com/authors/" + get_author_link(person) respone_author = requests.get(URL) soup_author = BeautifulSoup(respone_author.content, 'html5lib') - categories = soup_author.find_all('div', class_='kw-box') - check = False - count = 0 - for i in categories: - a = i.text - replace = a.replace("\n", '') - r = replace.lower() - if category in r: - check = True - count += 1 - - # Getting the quote of the related author - get_quote = soup_author.find_all('a', attrs={'title': 'view quote'}) + + # getting div of all quotes on page + all_quotes = list(soup_author.find_all('div', + {'class': [ + 'm-brick grid-item boxy bqQt qll-new-bg', 'm-brick grid-item boxy bqQt']} + )) quote_list = [] - big_list = [] - for i in range(count): - quote_list.append((get_quote[i].text, person)) - big_list.append(quote_list) + for quote in all_quotes: + # for each quote getting categories and matching them + categories_a_tag = quote.find_all( + 'a', {'class': 'qkw-btn btn btn-xs oncl_list_kc'}) + for category_a_tag in categories_a_tag: + if((category_a_tag.text).lower() == category.lower()): + # if category matches then get quote and append in quote_list + quote_a_tag = quote.find_all('a', {'title': 'view quote'}) + quote_list.append((quote_a_tag[0].text, person)) + break if len(quote_list) == 0: return('''Oops! It seems that there are no quotes of the author of that