Skip to content

how to parse unbullet list / tree list? #331

Answered by JJMC89
joycey97 asked this question in Q&A
Discussion options

You must be logged in to vote
import mwparserfromhell

text = """{{infobox
| ethnic_groups          = {{ublist |item_style=white-space:nowrap; |{{Tree list}}
*62.0% [[Singaporean]]
*9.1% [[Permanent residency in Singapore|Permanent resident]]
**71.1% Citizen/resident
*** 74.3% [[Chinese Singaporeans|Chinese]]
*** 13.5% [[Malay Singaporeans|Malay]]
*** 9.0% [[Indian Singaporeans|Indian]]
***3.2% [[Demographics of Singapore#Ethnic groups|Other]]
*28.9% [[Demographics of Singapore#Ethnic groups|Non-citizen/resident]]
{{Tree list/end}}
}}
}}
"""

wikicode = mwparserfromhell.parse(text)
infobox_tpl = wikicode.filter_templates()[0]  # select infobox
ethnic_groups = infobox_tpl.get('ethnic_groups').value  # parameter value o…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by earwig
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #328 on August 29, 2024 01:33.