How to search the summary in Portuguese by wikipedia API?

Asked

Viewed 491 times

-2

How do I get the API to return the string in en?

import wikipedia

pesquisa=wikipedia.summary(keyword)[0:150]
print(pesquisa)

1 answer

2

If it is the https://pypi.org/project/wikipedia/ define the language using:

wikipedia.set_lang("pt")

Thus:

import wikipedia

wikipedia.set_lang("pt") # Defina antes

pesquisa=wikipedia.summary(keyword)[0:150]
print(pesquisa)

See working in Repl.it

Note that Wikipedia only has pt, has not pt-BR, ie wikipedia in Portuguese meets Portugal and Brazil and probably other countries of the same language (of course I understand that there are variations, but within the articles themselves people try to adapt in the texts same)

  • How would that look in the code?

  • @Enzoportela is in the answer already, define before

  • @Enzoportela Anderson put a link in the answer too, with an example taken from en.wikipedia and pt.wikipedia

Browser other questions tagged

You are not signed in. Login or sign up in order to post.