Форум: Форум PHPФорум ApacheФорум Регулярные ВыраженияФорум MySQLHTML+CSS+JavaScriptФорум FlashРазное
Новые темы: 0000000
PHP на примерах (2 издание). Авторы: Кузнецов М.В., Симдянов И.В. Программирование. Ступени успешной карьеры. Авторы: Кузнецов М.В., Симдянов И.В. Самоучитель MySQL 5. Авторы: Кузнецов М.В., Симдянов И.В. PHP. Практика создания Web-сайтов (второе издание). Авторы: Кузнецов М.В., Симдянов И.В. Объектно-ориентированное программирование на PHP. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум Регулярные Выражения

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: Помогите с Яхо
 
 автор: lino   (24.08.2006 в 13:43)   письмо автору
 
 

Хочу написать функцию, берущую все ссылки из директории Yahoo-
вот код:
function get_yahoo_links($html){
$href='/<li>\s*<a\s*href=\S+(www\S*)\/>\s*(.*)\s*<\/a>\s*\r*\n*\s*-\s*(.*)\s*<\/li>/';
preg_match_all ($href, $html, $matches);
$result = array();
for ($k=0; $k< count($matches[0]); $k++){
$var[title] = $matches[2][$k];
$var[link] = $matches[1][$k];
$var[desc] = $matches[3][$k];
$result[] = $var;
}
return $result;
}

Почему то ничего не получается....
В чем может быть причина?
Заранее спасибо!

   
 
 автор: cheops   (24.08.2006 в 22:18)   письмо автору
 
   для: lino   (24.08.2006 в 13:43)
 

Укажите страницу с которой извелкаете ссылки?

   
 
 автор: lino   (25.08.2006 в 11:02)   письмо автору
 
   для: cheops   (24.08.2006 в 22:18)
 

Вот страница
http://dir.yahoo.com/Government/Web_Directories/
пишем такой код
<?
$html = file_get_contents("http://dir.yahoo.com/Government/Web_Directories/");
$href='/<li>\s*<a\s*href=\S+(www\S*)\/>\s*(.*)\s*<\/a>\s*\r*\n*\s*-\s*(.*)\s*<\/li>/';
preg_match_all ($href, $html, $matches);
$result = array();
for ($k=0; $k< count($matches[0]); $k++){
$var[title] = $matches[2][$k];
echo $var[title];
$var[link] = $matches[1][$k];
$var[desc] = $matches[3][$k];
$result[] = $var;
}

//return $result;
?>

что-то ничего не выдает.....

   
 
 автор: cheops   (25.08.2006 в 11:49)   письмо автору
 
   для: lino   (25.08.2006 в 11:02)
 

Вот из этого блока
<li><a href=http://rds.yahoo.com/S=139797:D1/CS=139797/SS=94958545/SIG=10q4onb4r/*http%3A//www.rulers.org/>Rulers</a>
 <img width=23 height=9 alt="[pick]" border="0" src=http://us.i1.yimg.com/us.yimg.com/i/pk/d_pick.gif><font face="Arial" size="-2"> [<a href="http://picks.yahoo.com/picks/i/20020605.html">read review</a>]</font>
 <a href=http://rds.yahoo.com/S=139797:D1/CS=139797/SS=94958545/SIG=10q4onb4r/*http%3A//www.rulers.org/ target=_blank><img src="http://us.i1.yimg.com/us.yimg.com/i/us/sch/bn/nw2.gif" height=11 width=11 border=0 alt="Open this result in new window"></a>
<br />
Features a list of rulers and heads of states for all countries dating back to 1700.<br />
<font color="green">www.rulers.org</font>
</li>

вас какая ссылка интересует? Последняя?

   
 
 автор: lino   (25.08.2006 в 11:53)   письмо автору
 
   для: cheops   (25.08.2006 в 11:49)
 

интересует перечень ссылок на странице-ссылка, название, описание.

   
 
 автор: cheops   (25.08.2006 в 13:11)   письмо автору
 
   для: lino   (25.08.2006 в 11:53)
 

Из указанного выше блока какой текст и ссылки нужны?

   
 
 автор: lino   (25.08.2006 в 13:42)   письмо автору
 
   для: cheops   (25.08.2006 в 13:11)
 

Ссылка - http://www.rulers.org
название - Rulers
описание - Features a list of rulers and heads of states for all countries dating back to 1700.
Как разложить...?

   
 
 автор: cheops   (25.08.2006 в 13:53)   письмо автору
 
   для: lino   (25.08.2006 в 13:42)
 

Можно поступить следующим образом
<?php
  $text 
file_get_contents("http://dir.yahoo.com/Government/Web_Directories/");
  
$pattern "|<li>[^>]+>(.*)</a>.*</a>(.*)<font[^>]+>([^<]+)</font>[\s]*</li>|isU";
  
preg_match_all($pattern$text$out);
  unset(
$out[0]);
  echo 
"<pre>";
  
print_r($out);
  echo 
"</pre>";
?>

   
 
 автор: lino   (25.08.2006 в 15:44)   письмо автору
 
   для: cheops   (25.08.2006 в 13:53)
 

Спасибо!

   
 
 автор: lino   (28.08.2006 в 09:43)   письмо автору
 
   для: lino   (25.08.2006 в 15:44)
 

Тут возникла проблемка....
Все хорошо работает -только в описаниях ссылок лишние теги....
Вот такие -как их убрать в каждом из описаний?
пример описания-
<a href=http://www.cutecats.com/ target=_blank></a>
<br />
Photo galleries and tidbits of kitty information where users can post their favorite cat albums.<br />

Как убрать все теги - кроме текста?
То есть нужно убрать
<a href=http://www.cutecats.com/ target=_blank></a>
<br />

и в конце <br />

   
 
 автор: lino   (02.09.2006 в 21:08)   письмо автору
 
   для: lino   (28.08.2006 в 09:43)
 

разобрался...

   
 
 автор: lino   (02.09.2006 в 21:13)   письмо автору
 
   для: lino   (02.09.2006 в 21:08)
 

Но скрипт парсинга Яхо перестал работать...Видимо-они что-то изменили в выдаче.
Выдает и перемешивает сами ссылки и названия....То есть берет 1-м элементом массива - одно название, а описание из элемента -другого....
Очень нужно поправить код для Яхи....

если у кого есть скрипт - выбирающий ссылки с названиями и описаниями из Яхи, или других каталогов зарубежных -помогите очень нужно!
Для всех-кроме dmoz...
Не работает вышеприведенный скрипт...

   
 
 автор: cheops   (02.09.2006 в 22:35)   письмо автору
 
   для: lino   (02.09.2006 в 21:13)
 

Приведите ссылку на страницу, где происходит сбой.

   
 
 автор: lino   (04.09.2006 в 09:39)   письмо автору
 
   для: cheops   (02.09.2006 в 22:35)
 

Вот
http://dir.yahoo.com/Government/Web_Directories/

   
 
 автор: lino   (04.09.2006 в 21:32)   письмо автору
 
   для: lino   (04.09.2006 в 09:39)
 

ссылка есть, жду Вашего совета...

   
 
 автор: cheops   (04.09.2006 в 22:43)   письмо автору
 
   для: lino   (04.09.2006 в 21:32)
 

Последнее выражение у меня выдало текст
<pre>Array
(
    [1] => Array
        (
            [0] => <b>Politics@</b>
            [1] => Rulers
            [2] => Governments on the WWW
            [3] => World World
            [4] => AdmiNet: World Governments
            [5] => Administracions a la Internet
        )

    [2] => Array
        (
            [0] => 
&nbsp;&nbsp;&nbsp;&nbsp;(<a href=http://us.rd.yahoo.com/dir/catpg/help/*http://help.yahoo.com/help/us/dir/basics/basics-21.html>What's This?</a>)</small></span><div class=cnt>Sites <b>1 - 10</b> of <b>10</b></div>
</td></tr>
<tr valign=top><td colspan=2><hr noshade></td></tr>
<tr><td height=1><spacer type="block" width="1" height="1"></td></tr>
<tr><td><div class=st><ul>
<li><a href=http://www.munisource.org/>Munisource.org</a>
<br />
Search for cities, towns, and municipal web sites world wide. Includes links to education, associations, and other resources.<br />

            [1] => ]</font>
<br />
Features a list of rulers and heads of states for all countries dating back to 1700.<br />

            [2] => 
<br />
Provides brief descriptions of, and links to, parliaments around the world. From the Inter-Parliamentary Union.<br />

            [3] => 
<br />
Comprehensive list of both United States and world councils of government, regional commissions, metropolitan planning organizations, regional governments, and agencies.<br />

            [4] => 
<br />
Offers a brief overview of the various forms of government seen throughout the world in the past and present.<br />

            [5] => 
<br />
Directory of federal, state, local, and tribal government web sites.<br />

        )

    [3] => Array
        (
            [0] => www.munisource.org
            [1] => www.rulers.org
            [2] => www.ipu.org/parline-e/parlinesearch.asp
            [3] => www.abag.ca.gov/abag/other_gov/rcg.html
            [4] => www.political-court.com
            [5] => www.govbrowser.com
        )

)
</pre>

Какую ссылку вы хотите исключить?

   
 
 автор: lino   (05.09.2006 в 12:32)   письмо автору
 
   для: cheops   (04.09.2006 в 22:43)
 

На странице 10 ссылок -а выдается в массиве только 5....
И потом смотрите-
Вот для одной ссылки все 3 значения из масивов-Название, описание, ссылка...
[2] => Governments on the WWW
[2] => <br />
Provides brief descriptions of, and links to, parliaments around the world. From the Inter-Parliamentary Union.<br />
[2] => www.ipu.org/parline-e/parlinesearch.asp

А на самом деле на странице мы видим
2-я ссылка
Governments on the WWW - название
Comprehensive database of governmental institutions and political parties that have web sites.-описание
www.gksoft.com/govt - это URL
Описание и URL в результате работы скрипта взяты из нижележащей ссылки-

PARLINE Database
Provides brief descriptions of, and links to, parliaments around the world. From the Inter-Parliamentary Union.
www.ipu.org/parline-e/parlinesearch.asp

И так во многих местах все перепутано. Посмотрите пожалуйста -надо сравнить оригинал страницы и то-что выводит скрипт.

   
 
 автор: Snorri   (05.09.2006 в 23:41)   письмо автору
 
   для: lino   (05.09.2006 в 12:32)
 

Делаю

<?
$text
=file_get_contents("http://dir.yahoo.com/Government/Web_Directories/");
$ptn="#<li><a.*?>([^<]+)<\/a>\s*<br />(.*?)<br />\s*<font color=\"green\">(.*?)<\/font>\s*<\/li>#is";
preg_match_all($ptn,$text,$out);
print_r($out);
?>

Получаю

[1] => Array
        (
            [0] => Munisource.org
            [1] => Governments on the WWW
            [2] => PARLINE Database
            [3] => World World
            [4] => Regional Councils of Government
            [5] => AdmiNet: World Governments
            [6] => Political Court
            [7] => Administracions a la Internet
            [8] => GovBrowser.com
        )

    [2] => Array
        (
            [0] => 
Search for cities, towns, and municipal web sites world wide. Includes links to education, associations, and other resources.
            [1] => 
Comprehensive database of governmental institutions and political parties that have web sites.
            [2] => 
Provides brief descriptions of, and links to, parliaments around the world. From the Inter-Parliamentary Union.
            [3] => 
An icon-based index of relevant links to world governments, world news and hundreds of information wells worldwide.
            [4] => 
Comprehensive list of both United States and world councils of government, regional commissions, metropolitan planning organizations, regional governments, and agencies.
            [5] => 
Includes links to official sites and other resources for world governments.
            [6] => 
Offers a brief overview of the various forms of government seen throughout the world in the past and present.
            [7] => 
Links to government Web sites worldwide with an emphasis on Catalan and Spanish sites.
            [8] => 
Directory of federal, state, local, and tribal government web sites.
        )

    [3] => Array
        (
            [0] => www.munisource.org
            [1] => www.gksoft.com/govt
            [2] => www.ipu.org/parline-e/parlinesearch.asp
            [3] => www.worldworld.com
            [4] => www.abag.ca.gov/abag/other_gov/rcg.html
            [5] => www.adminet.com/world/gov
            [6] => www.political-court.com
            [7] => www.blues.uab.es/mgp/governs
            [8] => www.govbrowser.com
        )

оно или нет?

   
 
 автор: lino   (07.09.2006 в 22:03)   письмо автору
 
   для: Snorri   (05.09.2006 в 23:41)
 

Да -сейчас верно...
ОНО!
Спасибо большое!

   
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования