Advertisement
Guest User

anime-planet.com xml anime exporter

a guest
Oct 19th, 2010
3,651
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 1 0
  1. #!/usr/bin/python
  2. #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
  3. #Additional info and packages:
  4. # Python 2.7 - http://python.org/download/
  5. # BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/#Download
  6.  
  7. from BeautifulSoup import BeautifulSoup,NavigableString
  8. import urllib2,sys,re,codecs
  9.  
  10. print 'This script will export your anime-planet.com anime list and saves it to anime-planet.xml'
  11. username = raw_input("Enter your username: ")
  12. baseURL = 'http://www.anime-planet.com/users/'+username+'/anime'
  13. html = urllib2.urlopen(baseURL).read()
  14. html = BeautifulSoup(html)
  15. pageNumber = int (html.find('li','next').findPrevious('li').next.contents[0])
  16. delimiter = '\t'
  17.  
  18. f = codecs.open('anime-planet.xml', 'w', 'utf-8')
  19. f.write ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
  20. f.write ('<myanimelist>\n')
  21.  
  22. print 'Exporting rough variant of myanimelist format...'
  23. for i in range(1,pageNumber+1):
  24.         baseURL = 'http://www.anime-planet.com/users/'+username+'/anime?page='+str(i)
  25.         html = urllib2.urlopen(baseURL).read()
  26.         html = BeautifulSoup(html)
  27.         for animeItem in html.findAll('tr')[1:]:
  28.                 animeItem = BeautifulSoup(animeItem.renderContents())
  29.  
  30.                 f.write ('\t<anime>\n');
  31.                 f.write ('\t\t<series_title><![CDATA['+ animeItem.a.text +']]></series_title>\n');
  32.                 f.write ('\t\t<series_type>' + animeItem.find('td','tableType').text + '</series_type>\n');
  33.                 f.write ('\t\t<my_watched_episodes>'+ animeItem.find('td','tableEps').text.replace('&nbsp;','1') +'</my_watched_episodes>\n');
  34.                 f.write ('\t\t<my_score>' + str(int(float(animeItem.img['name'])*2)) + '</my_score>\n');
  35.                 f.write ('\t\t<my_status>' + animeItem.find('td','tableStatus').text.replace('status box','') +'</my_status>\n');
  36.                 #f.write ('\t\t<update_on_import>1</update_on_import>\n');
  37.                 f.write ('\t</anime>\n\n');
  38.  
  39. f.write ('</myanimelist>\n')
  40. print 'Done, see anime-planet.xml'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement