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
- #Additional info and packages:
- # Python 2.7 - http://python.org/download/
- # BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/#Download
- from BeautifulSoup 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'
- f = codecs.open('anime-planet.xml', 'w', 'utf-8')
- f.write ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
- f.write ('<myanimelist>\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())
- f.write ('\t<anime>\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');
- f.write ('</myanimelist>\n')
- print 'Done, see anime-planet.xml'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement