-
Notifications
You must be signed in to change notification settings - Fork 79
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to parse unbullet list / tree list? #328
Comments
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 of interest
ubl_tpl = ethnic_groups.filter_templates()[0] # select {{ublist}}
ubl_stripped = ubl_tpl.get('1').value.strip_code() # stripped parameter value of interest
res = '\n'.join(l.strip() for l in ubl_stripped.splitlines()) # trim leading/trailing whitespace
print(res) |
@JJMC89 Thank you. How to list all "keys" (parameter names) from
in the Infobox? |
param_names = [p.name for p in infobox_tpl.params] |
Thank you! |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
for a section inside an Infobox:
how to use the package to parse this part to obtain:
The text was updated successfully, but these errors were encountered: