Quantcast
Viewing all articles
Browse latest Browse all 3593

[hautefeuille] Conversion de liens html en liens dokuwiki

Le langage informatique utilisé pour réaliser au mieux cette tâche est le langage Python.

Le module BeautifulSoup est également nécessaire pour cette fonction.

import BeautifulSoup

def main(source, dest):
    with open(source) as s:
        read_data = s.read()
        s.closed

    soup = BeautifulSoup.BeautifulSoup(read_data)

    mlis = [[item.get('href'), item.contents[0]] for item in soup.fetch('a') if item.contents]]

    with open(dest, 'w+') as d:
        [d.writelines('**%s** - %s \n\n'%(elem[1].encode('utf8'), elem[0].encode('utf8'))) for elem in mlis]
        d.closed

if __name__ == '__main__':
    main('bookmarks.html', 'bookmarks.txt')

Viewing all articles
Browse latest Browse all 3593

Trending Articles