Top Banner
the O2 Website Simon Lewis http://lewis.li - [email protected]
18

Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis - [email protected]@lewis.li.

Dec 13, 2015

Download

Documents

Jasper Glenn
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Why my iPhone sucks:

Screen Scraping the

O2 Website

Simon Lewis http://lewis.li - [email protected]

Page 2: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Overview

• Observations about the iPhone

• Why Screen Scrape?

• MMS solution

• Conclusions

Page 3: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Good Points(Before the Bashing)

• Web Browser

• SSL IMAP Email Client

• Alarm Clock

• Timer

Page 4: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Bad Points

• EDGE

• Bluetooth

• NO 3G

Wet piece of string is better connected

(Camera, Phone Interface, Text Message Interface)

Page 5: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

MMS?(maybe it’s not that popular)

ERROR

Page 6: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Mocking from O2

Page 7: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Message List Window

Page 8: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Beautiful Interface?

Page 9: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

• No web service available

• http://o2.co.uk/m not optimised for iPhone

There must be a better Solution...

• HTTP interface can be exploited

• iPhone Mail app is very nice: SSL IMAP

Problems:

Opportunities:

Page 10: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Screen Scraping?• Programmatically accessing webpage

content

• Parsing the contents of the page to extract the information you want

• Need a language suited to text parsing

Laziness - one of the principle virtues of a programmer

What tools are available?

Perl

Page 11: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

CPAN(Comprehensive Perl Archive Network)

use Config::IniFiles;use WWW::Mechanize;use Getopt::Long;use MIME::Lite;use YAML qw(LoadFile DumpFile);use Data::Dumper;use CGI qw(:standard);

Page 12: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

System Overview

lewis.li

o2.co.uk

iPhone1

2

3

4

5

Page 13: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Authentication

my $mech = WWW::Mechanize->new( autocheck => 1 );$mech->get( $site_url );$mech->submit_form( form_name => 'fm', fields => { msisdn => $user_name, pin => $user_password });

Page 14: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Inbox Listing

$mech->content =~ /From:.+?<p>(.+?)<\/p>.+?Subject:.+?<p>(.+?)<\/p>/s; my @mms_message_links = $mech->find_all_links( url_regex => qr/showMessage/ );my %unique_mms_links = map { $_, 1 } map { $_->url_abs } @mms_message_links;

Page 15: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Iterating through MMS

for my $option (@other_options){ $mech->current_form->value('selectedItem', $option); $mech->submit(); $filename = "/tmp/mms$message_part"; open $fh, "> $filename" or die "$filename: $!"; binmode $fh; print $fh $mech->content; close $fh; $mms_details->{$filename} = $mech->ct(); $mech->back();}

Page 16: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Creating the Email

my $msg = MIME::Lite->new( From =>"$sender", To =>"$mail_recipient", Subject =>"$subject", Type =>'multipart/mixed'); for my $part (keys %$mms_details) { ( my $nice_name = $part) =~ s!^/tmp/!!; if ($mms_details->{$part} eq 'image/jpeg') { $msg->attach(Type =>'image/jpeg', Path => $part, Filename =>"$nice_name.jpeg", Disposition => 'attachment'); }} $msg->send;

Page 17: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Receiving MMS via Email

Page 18: Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis  - simon@lewis.lisimon@lewis.li.

Conclusions

• CPAN had all the modules needed to automate interaction

• Messages on the O2 website expire. Email provides a good way to archive content

• WWW::Mechanize is very useful

• Radio buttons were the biggest challenge