#140 [en] 

I still prefer bs4, maybe it's because it was my first contact with html/xml parsers in Python. Also, it makes it easy to navigate the xml tree quite easily.

Here's a crude example that will print out all of a character's fames:

import sys
import requests
from bs4 import BeautifulSoup

url = "http://api.ryzom.com/character.php?apikey=xxxxxxxxxx"
r = requests.get(url)
data = r.text

soup = BeautifulSoup(data, 'xml')

#find all items
items = soup.find("fame").find_all()

for item in items:
print(item.name+" "+item.text+"\n")

But yes, ultimately not much different than your example.

Edited 2 times | Last edited by Laoviel (4 года назад)


My home is always sweet Yrkanis..

#141 [en] 

Python example to get api data, convert to json, and pretty print:

first install:
pip3 install requests xmltodict

#!/usr/bin/env python3

import json, requests, time, xmltodict

api = 'http://api.ryzom.com/time.php?format=xml'

response = requests.get(api)
jsondata = xmltodict.parse(response.text)
print(json.dumps(jsondata, sort_keys = True, indent = 4))

Last edited by Tgwaste (5 месяцев назад)


Last visit Tue Jan 31 07:42:56 2023 UTC

powered by ryzom-api