Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #This script will take your anime-planet.com username and scrape a list of your watched anime in XML utf-8 format to anime-planet.xml
- #Will also create an anime_list.txt file for all the anime that needs to be added manually. Note that the code will break if there are
- #special characters invovled... So remove the anime from your Anime-Planet list first.
- #Additional info and packages:
- # Python 2.7 - http://python.org/download/
- # BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/#Download
- from bs4 import BeautifulSoup,NavigableString
- import urllib2,sys,re,codecs
- print 'This script will export your anime-planet.com anime list and saves it to anime-planet.xml'
- username = raw_input("Enter your username: ")
- baseURL = 'http://www.anime-planet.com/users/'+username+'/anime'
- html = urllib2.urlopen(baseURL).read()
- html = BeautifulSoup(html)
- pageNumber = int (html.find('li','next').findPrevious('li').next.contents[0])
- delimiter = '\t'
- queryURL = 'http://mal-api.com/anime/search?q='
- f = codecs.open('anime-planet.xml', 'w', 'utf-8')
- f.write ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
- f.write ('<myanimelist>\n')
- animeList = []
- g = codecs.open('anime_list.txt', 'w', 'utf-8')
- g.write ('You will have to add these anime manually \n \n')
- print 'Exporting rough variant of myanimelist format...'
- for i in range(1,pageNumber+1):
- baseURL = 'http://www.anime-planet.com/users/'+username+'/anime?page='+str(i)
- html = urllib2.urlopen(baseURL).read()
- html = BeautifulSoup(html)
- for animeItem in html.findAll('tr')[1:]:
- animeItem = BeautifulSoup(animeItem.renderContents())
- animeName = '' + animeItem.a.text
- queryTitle = urllib2.urlopen(queryURL + animeName.replace(" ", "_")).read()
- f.write ('\t<anime>\n');
- animeID = queryTitle[7:queryTitle.find(',')]
- if animeID == '':
- animeList.append(animeName)
- print animeName
- g.write ("%s"%animeName + '\n')
- f.write ('\t\t<series_animedb_id>'+ animeID +'</series_animedb_id>\n');
- f.write ('\t\t<series_title><![CDATA['+ animeItem.a.text +']]></series_title>\n');
- f.write ('\t\t<series_type>' + animeItem.find('td','tableType').text + '</series_type>\n');
- f.write ('\t\t<my_watched_episodes>'+ animeItem.find('td','tableEps').text.replace(' ','1') +'</my_watched_episodes>\n');
- f.write ('\t\t<my_score>' + str(int(float(animeItem.img['name'])*2)) + '</my_score>\n');
- f.write ('\t\t<my_status>' + animeItem.find('td','tableStatus').text.replace('status box','') +'</my_status>\n');
- #f.write ('\t\t<update_on_import>1</update_on_import>\n');
- f.write ('\t</anime>\n\n');
- print 'Done, see anime-planet.xml and anime_list.txt'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement