Web Apps


uiWebPrevious12345678910uiWebNext

#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 years ago)

---


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 (4 months ago)

---

Tgwaste
uiWebPrevious12345678910uiWebNext
 
Last visit Tue Dec 6 13:52:15 2022 UTC
P_:

powered by ryzom-api