2016-01-11 6 views
0
use strict; # safety net 
use warnings; # safety net 
use feature 'say'; # a better "print" 

use Mojo; 
my $dom = Mojo::DOM->new; 
my $ua = Mojo::UserAgent->new; 
$dom= $ua->get('http://search.cpan.org/faq.html')->res->dom; 
my $desc=$dom->at('#u')->text; 

При запуске этого кода произошла ошибка выше. Это моя форма данных ввода, следующая с ссылкой на веб-страницу. thisНевозможно вызвать метод «текст» по неопределенному значению в строке sample.pl 11

Мне нужен вывод, как это только ответы.

CPAN Search is a search engine for the distributions, modules, docs, and ID's on CPAN. It was conceived and built by Graham Barr as a way to make things easier to navigate. Originally named TUCS [ The Ultimate CPAN Search ] it was later named CPAN Search or Search DOT CPAN. 

    If you are having technical difficulties with the site itself, send mail to [email protected] and try to be as detailed as possible in your note describing the problem. 

пожалуйста кто-нибудь может помочь мне

+1

#u ищет HTML-элемент с идентификатором = и. На этой странице нет. Читайте на селекторах css: http://www.w3schools.com/cssref/css_selectors.asp – Miller

ответ

1

Что-то вроде этого:

perl -Mojo -le 'print r g("http://search.cpan.org/faq.html")->dom("#cpansearch > div.pod > p")->map("text")->to_array;'