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 4337962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:01:03+00:00 2026-05-21T11:01:03+00:00

I am looking to retrieve the XML of a Wikipedia page using their api.

  • 0

I am looking to retrieve the XML of a Wikipedia page using their api. The URL I’m using is the following: http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=dog

I’ve seen this, but it hasn’t helped. No matter what I do, I’m not actually getting anything returned to $c, and I can’t figure out why. I can do file_get_contents with a plain text file, and it works just fine. Can anyone else verify that this works?

<?php
$url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
$c = file_get_contents($url);
echo $c;
?>

EDIT I have also tried the cURL available on that page, which also doesn’t work:

$url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$c = curl_exec($ch);
echo $c;
  • 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-05-21T11:01:04+00:00Added an answer on May 21, 2026 at 11:01 am

    wikipedia requires you specify a descriptive user agent, by doing something like this:

    <?php
    $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_USERAGENT, "MyCoolTool (+http://example.com/MyCoolToolPage/)");
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $c = curl_exec($ch);
    echo $c;
    ?>
    

    You should use a user-agent string that describes your site, and you shouldn’t spoof a web browser’s user agent or you may be blocked for appearing suspicious (source: WikiMedia User-Agent policy)

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

Sidebar

Related Questions

I'm looking to retrieve an XML document from a private API, then parse it
How do you retrieve selected text using Regex in C#? I am looking for
I was looking for a way to retrieve Google search results, using RoR. I
I'm using PostgreSQL's Ltree module for storing hierarchical data. I'm looking to retrieve the
I'm using GData as my XML parser. I've tried using an XPath query to
I am looking to retrieve all email templates using Force.com ant migration tool. I
I'm looking to retrieve the latest two posts from a Blogger.com account that belongs
I am looking for a way to retrieve the certificate chain of a targeted
I am looking for a way to retrieve the surrounding rows in a NHibernate
I am looking for a way to retrieve the variable name, so I don't

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.