[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Парсим ютуб как нубы
Agahnim
Давно меня не было :) Собственно, помогите разобраться. С помошью API Youtube я получаю хмл документ.
Пример:
Свернутый текст
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'
xmlns:batch='http://schemas.google.com/gdata/batch'
xmlns:yt='http://gdata.youtube.com/schemas/2007'
xmlns:gd='http://schemas.google.com/g/2005'
gd:etag='W/"CEEERnk_fCp7ImA9WxRUEU4."'>
<
id>tag:youtube.com,2008:channels</id>
<
updated>2008-11-19T14:10:07.744-08:00</updated>
<
category scheme='http://schemas.google.com/g/2005#kind'
term='http://gdata.youtube.com/schemas/2007#channel'/>
<
title>YouTube Channels matching query: soccer</title>
<
logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/channels?v=2'/>
<
link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/channels/batch?v=2'/>
<
link rel='self' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/channels?q=soccer&start-index=11&max-results=1 0&v=2'/>
<
link rel='service' type='application/atomsvc+xml'
href='http://gdata.youtube.com/feeds/api/channels?alt=atom-service&v=2'/>
<
link rel='next' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/channels?q=soccer&start-index=21&max-results=1 0&v=2'/>
<
author>
<
name>YouTube</name>
<
uri>http://www.youtube.com/</uri>
</author>
<
generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator>
<
openSearch:totalResults>6141</openSearch:totalResults>
<
openSearch:startIndex>1</openSearch:startIndex>
<
openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<
entry gd:etag='W/"CEEERnk_fCp7ImA9WxRUEU4."'>
<
id>tag:youtube.com,2008:channel:dXNzb2NjZXJkb3Rjb20</id>
<
updated>2008-11-19T14:10:07.744-08:00</updated>
<
category scheme='http://schemas.google.com/g/2005#kind'
term='http://gdata.youtube.com/schemas/2007#channel'/>
<
category scheme='http://gdata.youtube.com/schemas/2007/channeltypes.cat'
term='director'/>
<
title>U.S. Soccer</title>
<
summary>
ussoccer.com's comprehensive coverage of the U.S. National Teams welcomes
fans to our YouTube channel - including interviews, press conferences...
</summary>
<link rel='
http://gdata.youtube.com/schemas/2007#featured-video'
type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/videos/bYKugypF8HA?v=2'/>
<
link rel='alternate' type='text/html'
href='http://www.youtube.com/profile?user=ussoccerdotcom'/>
<
link rel='self' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/channels/dXNzb2NjZXJkb3Rjb20?v=2'/>
<
author>
<
name>ussoccerdotcom</name>
<
uri>http://gdata.youtube.com/feeds/api/users/ussoccerdotcom</uri>
</author>
<
gd:feedLink rel='http://gdata.youtube.com/schemas/2007#channel.content'
href='http://gdata.youtube.com/feeds/api/users/ussoccerdotcom/uploads?v=2'
countHint='513'/>
</
entry>
</
feed>


Я сделал простой скрипт на симпле чтобы вывести ID и Название видео -

<?php
include('url.lib.php');
$sxml = simplexml_load_file($caflastones);
foreach ($sxml->feed as $item) {
echo $item->entry->id;
echo $item->entry->title;
}
?>

Только он почемуто не подчиняется мне и выводит пустоту. Может я чтото пропустил?

P.S. $caflastones - ссылка на фид прописанная в url.lib.php.



Спустя 10 минут, 20 секунд (16.08.2011 - 14:16) Invis1ble написал(а):
Agahnim
попробуй для начала
$sxml = simplexml_load_file($caflastones) or die('Could not load file');

Спустя 2 минуты, 26 секунд (16.08.2011 - 14:19) Agahnim написал(а):
Цитата (Invis1ble @ 16.08.2011 - 11:16)
Agahnim
попробуй для начала
$sxml = simplexml_load_file($caflastones) or die('Could not load file');

Не мрет - значит работает. Я проверял уже так.

Спустя 34 минуты, 33 секунды (16.08.2011 - 14:53) Agahnim написал(а):
Проблема решена путем перехода с атом фида на обычный rss
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2025 Invision Power Services, Inc.