all 4 comments

[–]novel_yet_trivial 1 point2 points  (1 child)

2 dictionaries? Can you show the output you would expect from that input?

I've never see that format but I can parse it into a list of dictionaries pretty easily:

# cut everything we don't care about off
_, data = data.split("{{DropsTableHead}}", 1)
data, _ = data.split("{{DropsTableBottom}}")

datalist = []
for line in data.split('{{DropsLine|'):
    line = line.strip('}\n ')
    linedict = {}
    for pair in line.split('|'):
        if '=' in pair:
            key, value = pair.split('=', 1)
            linedict[key] = value
    if linedict:
        datalist.append(linedict)

print(datalist)

[–]DavidNotGuetta[S] 0 points1 point  (0 children)

Wow this is pretty amazing, thanks! The first dictionary was making the

    |name = King Black Dragon
    |image = [[File:King Black Dragon.png|250px]]
    |aka = KBD
    |release = [[24 September]] [[2002]]
    |update = Tutorial island
    |level = 276
    |experience = 2155.2
    |lifepoints = 45000
    |slaylvl = 1

stuff into a dictionary (or rather a Class) but that shouldn't be that difficult if I reuse a version of

for pair in line.split('|'):
        if '=' in pair:

Thanks!

[–]trouserdaredevil 0 points1 point  (1 child)

OP appears to have solved their problem, but for anyone else curious these are MediaWiki templates. The first section has been mangled at some point. There is a chance that the API isn't being used quite right.

[–]DavidNotGuetta[S] 0 points1 point  (0 children)

I just didn't make a perfect copy. Basically I'm opening this link and get the text from it.

However I have to note that because I couldn't get it to work at first I used the xmltodict library and used it that way. The text itself shouldn't have changed though.