usestrict;usewarnings;usefeatureqw/say/;useData::Dumper;useEncodeqw/encode_utf8/;useURIqw/new/;useWeb::Scraperqw/scraper/;# connpassのフィード欄を取得したいmy$url=URI->new('https://perl-entrance-tokyo.connpass.com/event/89771/');# 取得したいフィード欄(ページ下部)は# xpathで# <div class="group_box" id="feed"># のタグで囲まれた範囲の# thumb36_list# というclass属性を持つdiv。# これをscrapeする。## コメントしている複数のユーザの情報を取得したいので、# 返り値は配列リファレンスmy$scraper=scraper{process'//div[@id="feed"]//div[contains( @class , "thumb36_list" )] ','feeds[]'=>scraper{# 上記xpath内をさらにscrapeする# class 属性が date の pタグのTEXT部を取得するprocess'//p[@class="date"]','time'=>'TEXT',# class 属性が message の pタグの中にあり、# 最初に出現するaタグのTEXT部を取得するprocess'//p[@class="message"]/a[1]','user'=>'TEXT',# class 属性が message の pタグのTEXT部を取得するprocess'//p[@class="message"]','action'=>'TEXT',# class 属性が icon_comment の spanタグのTEXT部を取得するprocess'//span[@class="icon_comment"]','comment'=>'TEXT',}};# スクレイピングを実行するmy$res=$scraper->scrape($url);# スクレイピングした結果の配列リファレンスを表示するformy$feed(@{$res->{feeds}}){say'-'x10;sayencode_utf8($feed->{time});sayencode_utf8($feed->{user});sayencode_utf8($feed->{action});sayencode_utf8($feed->{comment})//'';#コメントが空の場合がありうる}
Comments (1)
bend loyed
We will really benefit from edu email, and you may even obtain free or discounted software if you use it. If you have any spare time, you may join me in playing monopoly online
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.
We will really benefit from edu email, and you may even obtain free or discounted software if you use it. If you have any spare time, you may join me in playing monopoly online