# pywikibot documentation: https://github.com/wikimedia/pywikibot/blob/master/pywikibot/page.py

import pywikibot
from pywikibot import pagegenerators

import re

site = pywikibot.Site('en', 'wikipedia')
cat = pywikibot.Category(site,'Category:Requests_for_audio_pronunciation')

requests = cat.subcategories()


for page in requests:
    lang_template = re.search('\((.+)\)',page.title())
    if lang_template:
        print('Language: ' + lang_template.group(1))
    gen = pagegenerators.CategorizedPageGenerator(page)
    for x in gen:
        print(x.title())

# Search pronunciations in Forvo?
# https://github.com/edoput/ForvoDownloader
Language: Afrikaans
Stellenbosch
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-df899d383340> in <module>()
     37     for x in gen:
     38         print(x.title())
---> 39         getEnglishPronunciation(x.title())
     40 
     41 # Search pronunciations in Forvo?

<ipython-input-1-df899d383340> in getEnglishPronunciation(word)
     12 def getEnglishPronunciation(word):
     13     webPageUrl = "https://forvo.com/word/%s/#en" % word
---> 14     webPageText = requests.get(webPageUrl).text
     15     englishPageTextList = re.findall("<em id=\"en.*?</article>", webPageText, re.DOTALL)
     16     if len(englishPageTextList) == 0:

AttributeError: 'generator' object has no attribute 'get'