Changeset 1769
- Timestamp:
- 11/19/07 03:30:51 (10 months ago)
- Location:
- lang/perl/Net-Kotonoha/trunk
- Files:
-
- 1 added
- 1 modified
-
README (added)
-
lib/Net/Kotonoha.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Net-Kotonoha/trunk/lib/Net/Kotonoha.pm
r1224 r1769 8 8 use HTML::Selector::XPath qw/selector_to_xpath/; 9 9 use HTML::TreeBuilder::XPath; 10 use HTML::Entities qw/decode_entities/; 10 11 use Net::Kotonoha::Koto; 11 12 … … 63 64 my $self = shift; 64 65 my $xpath = shift; 66 my $page = shift || 'http://kotonoha.cc/home'; 65 67 66 68 $self->login unless defined $self->{loggedin}; 67 69 68 my $res = $self->{mech}->get( 'http://kotonoha.cc/home');70 my $res = $self->{mech}->get( $page ); 69 71 croak "can't login kotonoha.cc" unless $res->is_success; 70 72 return unless $res->is_success; … … 91 93 } 92 94 95 sub _get_stream { 96 my $self = shift; 97 my $xpath = shift; 98 my $page = shift || 'http://kotonoha.cc/stream'; 99 100 $self->login unless defined $self->{loggedin}; 101 102 my $res = $self->{mech}->get( $page ); 103 croak "can't login kotonoha.cc" unless $res->is_success; 104 return unless $res->is_success; 105 106 my @list; 107 108 my $tree = HTML::TreeBuilder::XPath->new; 109 $tree->parse($res->content); 110 $tree->eof; 111 foreach my $line ($tree->findnodes(selector_to_xpath($xpath))) { 112 my $html = decode_entities($line->as_HTML); 113 if ($html =~ /<a href="\/user\/(\w+)">([^<]+)<\/a>[^<]+<a href="\/no\/(\d+)">([^<]+)<\/a>([^ ]+)( [^ ]+ (.+))?$/) { 114 push @list, { 115 user => $1, 116 name => $2, 117 comment => $7 || '', 118 answer => $5, 119 koto_no => $3, 120 title => $4, 121 } 122 } 123 } 124 $tree->delete; 125 return @list; 126 } 127 93 128 sub newer_list { 94 129 return shift->_get_list('dl#newkoto a'); … … 97 132 sub recent_list { 98 133 return shift->_get_list('dl#recentkoto a'); 134 } 135 136 sub hot_list { 137 return shift->_get_list('dl#hot20 a'); 138 } 139 140 sub answered_list { 141 return shift->_get_list('dl#answeredkoto a'); 142 } 143 144 sub posted_list { 145 return shift->_get_list('dl#postedkoto a'); 146 } 147 148 sub stream_list { 149 return shift->_get_stream('dl#stream li'); 150 } 151 152 sub subscribed_list { 153 return shift->_get_stream('dl#subscribelist li', 'http://kotonoha.cc/inbox'); 99 154 } 100 155
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)