SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Mojo::UserAgent
かわいい
~ use Mojolicious as HTTP client ~
2013-09-19 @ LT-thon in YAPC::Asia 2013
turugina
皆さん、
Mojolicious
好きですか?
ですよね
Mojolicious
萌え♡
Mojolicious
萌え♡
みんな大好きMojolicious
● http://mojolicio.us/
● 現在のバージョン: 4.39 (2013-09-16)
Mojolicious has...
● Web Server (HTTP, HTTPS, WebSocket)
○ Mojo::Server::*
● CLI Framework
○ Mojolicious::Command::*
○ test, cpanify, print routes, run as CGI,
○ you can write your own commands
● UserAgent (HTTP/WebSocket client)
○ Mojo::UserAgent, Mojo::Transaction::*
○ Mojo::Cookie::
○ DOM/Selectors
● ojo module (for one-liner)
○ perl -Mojo -E ‘b(g(“mojolicio.us”)->body)-
>html_unescape->say’
As HTTP UserAgent
Mojo::UserAgent
Mojo::UserAgent::Transactor
Mojo::Transaction::HTTP
Mojo::Message::Request
Mojo::Message::Response
use
Basic Usage
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
my $tx = $ua->get(‘URL’ => Header =>BODY);
if ( my $res = $tx->success) {
# $res をつかってごにょごにょ
} else {
my ($msg, $code) = $tx->error;
die “$msg: $code”;
}
Get
my $tx = $ua->post(‘http://www.example.com/login’, form
=> { username => ‘scott’, password => ‘tiger’ });
if ( my $res = $tx->success ) {
for my $cookie (map {$_->res->cookies} @{$tx-
>redirects}) {
if ( $cookie->name eq ‘PHPSESSID’ ) {
# ごにょごにょ
}
}
}
Put
my $cookie = Mojo::Cookie::Response->new;
$cookie->name(‘PHPSESSID’);
$cookie->value($phpsessid);
$cookie->path(‘/’);
$ua->cookie_jar->add($cookie);
Scraping
my $coll = $res->dom(‘section#illust_list ul li a.work’);
# $coll … Mojo::Collection
$coll->each(sub {
my ($e, $count) = @_;
my $title = $e->find(‘h1’)->first->text;
my $img_url = $e->find(‘img’)->first->attr(‘src’);
# ごにょごにょ
});
JSON
my $tx = $ua->post(‘...’, json => {loren => ‘ipsum’});
# assuming json in response:
# { “result”: “ok”, “body”: {“title”: “hogehoge”} }
if (my $res = $tx->success) {
if ( $res->json(‘/result’) eq “ok” ) {
say $res->json(‘/body/title’);
}
}
ByteStream
use Mojo::ByteStream;
my $tx = $ua->get(‘http://.../foo.jpg’);
if ( my $res = $tx->success ) {
my $bs = Mojo::ByteStream->new($res->body);
$bs->spurt(‘/tmp/foo.jpg’);
say “MD5: “, $bs->md5_sum;
}
普通に使う分には
超
優 秀
Mojo::UserAgent
Mojo::Server
優秀な子たちですから
Easy to mashup
Mojo::UserAgent
Mojo::Server
the Internet
Data
myapp
Cache/DB
HTML, js,...
Service
と、いうのを
2日くらいで作ってみた
けどデータ元がpixivで自分のアカウントでログイン
してるから公開はできない
2013-09-23追記: pixivのアカウント情報はバージョン管理に
入ってないことを確認したのでコード晒してみます:
https://code.launchpad.
net/~turugina/+junk/illust_sns_viewer
但し、このコードを使ってpixivさんに迷惑はかけないように!
概要
Mojo::UserAgent
Mojo::Server
pixiv
検索結果
画像
myapp
DBM
File Cache
jQuery. Gallarie
「艦これかわいい」
艦これ KAWAII!
http://www.pixiv.net/member_illust.php?mode=medium&illust_id=38587771
Demo
ご清聴ありがとうございました

Contenu connexe

En vedette

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

En vedette (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Mojo::UserAgentかわいい (@ YAPC::Asia2013 前夜祭 LT-thon 2013-09-19)