How to get 100 characters from wikipedia api

I want to retrieve 100 characters from Wikipedia API
searching i got all the text content but i just need 100 characters
here is my Code

<div id="article"></div>

<script type="text/javascript">


	    type: "GET",
	    url: "",
	    contentType: "application/json; charset=utf-8",
	    async: false,
	    dataType: "json",
	    success: function (data, textStatus, jqXHR) {
		var markup = data.parse.text["*"];
		var i = $('<div></div>').html(markup);
		// remove links as they will not work
		i.find('a').each(function() { $(this).replaceWith($(this).html()); });
		// remove any references
		// remove cite error
	    error: function (errorMessage) {

can any one help me in this? please,

How / where are you determining that you’re getting the text content? In the <div></div> / a elements?

@Mittineague Yes, In

<div id="article"></div>
1 Like

And currently it gets everything starting with
<div class=\"mw-parser-output\">
and ending with the closing </div> ?

There’s an awful lot of HTML in the content. You want to not truncate in a way that breaks a tag or causes it to not be well-formed. Can you limit the value to text content only with no HTML tags? Once you get that far it should be easy enough to use a string function to get something like:
“blah, blah blah 100 characters ‘… ellipsis here’”

1 Like

Got the answer as simple
by changing



$('#article').html($(i).find('p').text().slice(0, 100));
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.