Hey everyone! I’m working on a Discord bot and I want it to pull anime stats from MyAnimeList profiles. You know, stuff like how many shows they’ve finished, what they’re watching now, and what they’ve given up on.
I’ve been trying to figure out how to grab this info from a user’s profile page (the one you get to by adding their username after MyAnimeList.net/profile/). But I’m stuck. I can’t seem to find the right way to get at that data.
Does anyone have experience with this? What’s the best approach to scrape or access this kind of info from MAL profiles? Any tips or code snippets would be super helpful!
Thanks in advance for any advice you can give me on this!
I’ve tackled a similar project before, and I found that using the Jikan API is a solid approach for fetching MAL data. It’s an unofficial API, but it’s well-maintained and doesn’t require scraping.
Here’s a basic Python snippet to get you started:
import requests
def get_user_stats(username):
url = f'https://api.jikan.moe/v4/users/{username}/statistics'
response = requests.get(url)
if response.status_code == 200:
data = response.json()['data']
return {
'completed': data['anime']['completed'],
'watching': data['anime']['watching'],
'dropped': data['anime']['dropped']
}
return None
# Usage
stats = get_user_stats('username_here')
print(stats)
This method is more reliable than web scraping and less likely to break with website updates. Just remember to implement rate limiting to stay within Jikan’s usage guidelines.
hey, have u tried using the jikan API? it’s not official but works pretty well for getting MAL data without scraping. u can fetch user stats easy with it. just remember to add some rate limiting so u don’t overload it. here’s a quick python example:
import requests
def get_stats(user):
r = requests.get(f’https://api.jikan.moe/v4/users/{user}/statistics’)
if r.ok:
return r.json()[‘data’][‘anime’]
print(get_stats(‘someuser’))
I’ve worked on similar projects and found that relying on web scraping for MAL profiles can be problematic over time. Changing site structures and rate limits can easily break your implementation. Instead, consider using the Jikan API, an unofficial but robust alternative. You can use it to reliably fetch user stats without scraping the web page directly. A simple Python snippet demonstrates how to retrieve completed, watching, and dropped anime stats. Just ensure you handle errors and respect the API’s rate limits in your Discord bot.