Jump to content

Downloading xml file from atom / rss feeds using CURL


Recommended Posts

Hi, I am trying to download xml file from URLs containing feeds using CURL using the following code. The code downloads the xml file for LINK1 (below, for RSS feeds). The code downloads a HTML file (instead of xml) for LINK2 (below, for Atom feeds). If I open LINK2 in a browser I can save it as a xml file. I do not understand why the code cannot download the xml file for LINK2. Any help will be highly appreciated.

//$url = 'https://rss.sciencedirect.com/publication/science/00221694'; //LINK1
$url = 'https://onlinelibrary.wiley.com/feed/25780727/most-recent'; //LINK2

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080311 Firefox/');

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);

$myfile = fopen('x.xml', "w") or die("Unable to open file!");
fwrite($myfile, $resp);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...