コード例 #1
0
def build_menu_item_links(soup):
    link_map = {}

    chapters = soup.find_all("div", class_="chapter-content-container")
    for chapter in chapters:
        heading = chapter['id'].rstrip('-child')

        menu_items = {}
        items = chapter.find_all("div", class_="menu-item")
        for item in items:
            subheading = item.p.text.strip().replace(' ', '_')
            subheading = DownloadList.replace_punctuation(subheading)
            href = item.a['href']
            href = 'https://courses.edx.org/' + href if 'http' not in href else href
            menu_items[subheading] = href

        link_map[heading] = menu_items

    return link_map
コード例 #2
0
def build_menu_item_links(soup):
    link_map = {}

    chapters = soup.find_all("div", class_="chapter-content-container")
    for chapter in chapters:
        heading = chapter['id'].rstrip('-child')

        menu_items = {}
        items = chapter.find_all("div", class_="menu-item")
        for item in items:
            subheading = item.p.text.strip().replace(' ', '_')
            subheading = DownloadList.replace_punctuation(subheading)
            href = item.a['href']
            href = 'https://courses.edx.org/' + href if 'http' not in href else href
            menu_items[subheading] = href

        link_map[heading] = menu_items

    return link_map
コード例 #3
0
 def test_replace_punctuation(self):
     self.assertEqual(DownloadList.replace_punctuation(''), '')
     self.assertEqual(DownloadList.replace_punctuation('123'), '123')
     self.assertEqual(DownloadList.replace_punctuation(string.punctuation), '--------------------------_-----')