I am trying to find a way to retrieve user stats from a given user's "My Anime List" profile and can't figure out how to retrieve the data. I am looking to find their completed, watching, dropped etc from their profile (Found using MyAnimeList.net/profile/<insert user name here>
).
How would I go about doing this?
The official MyAnimeList API doesn't have any endpoints for getting user profile info. What you can do is scrape the webpage.
System.Xml
namespace, such asXDocument.Parse()
. There's a lot of resources for help doing that here on StackOverflow.If you're unsure of how to get this data from the web in the first place, I'd recommend looking into libraries like RestSharp or Flurl. They abstract a way a lot of the boilerplate for getting info from the web for you so you can just focus on coding. If you want to skip both the XML parsing and web requests altogether, you can let a library do it for you.
To keep your Discord.NET bot clean, I'd recommend having a
MyAnimeListService
class that you do this web request/scraping in. You can then inject it into the module you're using for your (I assume)!anime
command and focus on using the MAL profile data there. This way, you're separating the logic of getting the data from the logic of presenting the data to your Discord users. You can read about dependency injection in Discord.NET here. Assuming you're using C#, the end result would be accessing the module like this: