Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8725379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:01:42+00:00 2026-06-13T08:01:42+00:00

I wish to extract the the first image within infobox – the table with

  • 0

I wish to extract the the first image within infobox – the table with the class name infobox that is on most Wikipedia pages, using Wikipedia/Mediawiki API

Here’s what I’ve tried so far –

$.getJSON("http://en.wikipedia.org/w/api.php?action=mobileview&format=json&page=mumbai&redirect=no&sections=0&prop=text&sectionprop=toclevel%7Clevel%7Cline%7Cnumber%7Cindex%7Cfromtitle%7Canchor&callback=?", function(json) { 
var wikitext = json.mobileview.sections[0].text;
var img = $(wikitext).find('img:first').attr("src");

/*
//how can i make this work?

//selector for element with multiple classes - http://stackoverflow.com/questions/1041344/jquery-multiple-class-selector
  var infoboximg = $(wikitext).find('table.infobox.geography.vcard img:first').attr("src");
console.log(infoboximg);  
*/

$('#pic').append('<img src="http://' + img + '" />');

}
);          

You can try the snippet here – http://jsbin.com/erudum/5/

How can I fix the code to grab the first image within the table having the name infobox?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:01:44+00:00Added an answer on June 13, 2026 at 8:01 am

    Do you need to get the src only? why not just append the img like this

    $.getJSON("http://en.wikipedia.org/w/api.php?action=mobileview&format=json&page=mumbai&redirect=no&sections=0&prop=text&sectionprop=toclevel%7Clevel%7Cline%7Cnumber%7Cindex%7Cfromtitle%7Canchor&callback=?", function(json) { 
            var wikitext = json.mobileview.sections[0].text;
            var img = $(wikitext).find('img:first');
            $('#pic').append(img);
        }
    );
    

    http://jsfiddle.net/wirey00/Kr46e/

    EDIT

    After looking at the return text.. it is actually an array of ELEMENTS that’s returned.. The table is the 5th element so you can get it use the .eq() method in jQuery

    $.getJSON("http://en.wikipedia.org/w/api.php?action=mobileview&format=json&page=mumbai&redirect=no&sections=0&prop=text&sectionprop=toclevel%7Clevel%7Cline%7Cnumber%7Cindex%7Cfromtitle%7Canchor&callback=?", function(json) { 
            var wikitext = json.mobileview.sections[0].text;
            var img = $(wikitext).eq(4).find('img:first').attr('src');
            $('#pic').append('<img src="' + img + '"/>');
        }
    );
    

    You can do a console.log to see what I mean

    console.log($(wikitext));
    

    http://jsfiddle.net/wirey00/Jp7rn/

    EDIT AGAIN

    I figured out why it’s coming back as an array. The quotes in the text is throwing it off. What I would do is append the whole thing.. maybe to a hidden field or something.. then traverse it and get the img text. then remove the whole thing again. Here’s an example

    $.getJSON("http://en.wikipedia.org/w/api.php?action=mobileview&format=json&page=mumbai&redirect=no&sections=0&prop=text&sectionprop=toclevel%7Clevel%7Cline%7Cnumber%7Cindex%7Cfromtitle%7Canchor&callback=?", function(json) { 
        var wikitext = json.mobileview.sections[0].text;
        $('#pic').hide().append(wikitext); // hide the div then append whole string
        var img = $('#pic').find('.infobox img:first').attr('src');// find the src
        $('#pic').show().html('<img src="' + img + '"/>'); // show and append
        }
    );
    

    http://jsfiddle.net/Jp7rn/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to extract the image using ALAssetsLibrary and ALAsset directly in the form
I have a table that I need to extract data from, and wish to
I wish to extract just the first 1024 bytes of a stored blob and
I have a table and I wish to extract the html from a specific
I have a lot of log files that I wish to extract the distinct
I wish to extract rows and columns from a matrix using a single fancy
i have no idea about php regex i wish to extract all image tags
I have JSON similar to this . I wish to extract values like name,
From this html source: <div class=category_link> Category: <a href=/category/personal>Personal</a> </div> I wish to extract
I have a moderately sized dataset in excel from which I wish to extract

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.