SlideShare a Scribd company logo
1 of 26
Download to read offline
FPSゲームで勝ちたいから、
プレイヤーを分析したい!
VOL_1:PYTHONでスクレイピングし、データを集める!
自己紹介
東部 (トウベ)
近畿大学工学部情報学科4年生
趣味:写真撮影、無駄にCGが良いFPSのクソゲー(BFV)のプレイ、Vtuber
最近の出来事:
・研究で使用予定の簡易脳波計の3rdパーティー向けSDKがBaidu(百度)にうpされていたため
DLできなくて早くも卒研の見通しが悪化した(解消済み)
・引きこもり過ぎてVtuberに沼落ちしました
目的
BattleFieldというFPSゲームを前からずっとプレイしていた
どうすれば常連の廃人ゲーマーと渡り合えるのか気になった
このゲームにはトラッカーサイトがあって個人の戦績や一試合ごとの結果が見れる (他にも
APEXやフォートナイトもあるよ)
分析すればよい知見が得られかもしれない
バトルフィールドVってどんなゲーム?
WW2がモデルの無駄にCGのクオリティが高いクソ
シューティングゲームシリーズの最新作
ドイツの報復兵器V1が空から降ってきたり、
日本軍が鬼畜米兵の戦車相手に爆弾のついた槍で特攻してきます
※政治要素はないよ
なお、様々な要因にてつい先ほど、事実上の打ち切りである追加開発が無くなりました()
Tracker Network (BFVのページ)
Traker Network
実はいつくかのゲームにはAPIがあり、データ取得できる
だがしかし、不人気なBFにはない!
(同じEAのApexにはあるのにね(笑))
そこでPythonでスクレイピングすることで
データを抜き取るよ!
スクレイピングとは?
「Webページから必要な情報を抜き出す作業のこと」
混同されやすい用語として、クローリングがある
「Webページのハイパーリンクをたどって
次々にWebページをダウンロードする作業」
つまり、
クローリングなどでDLしたWebページ(HTML)から
必要な情報だけを取り出すのがスクレイピング
Pythonでスクレイピングするには
スクレイピングに関係する代表的なライブラリ(フレームワーク)
・Beautiful Soup:HTMLおよびXMLドキュメントを解析するためのパッケージ
・Scrapy:クローラ実装するためのフレームワーク
今回は前者を使用
Requestsライブラリを使ってHTMLをダウンロードして、
BeatifulSoupのHTMLパーサーで必要な情報を抜き出す
パーサー:一定の規則で記述されたテキストを解析し、プログラムで扱い やすいよ
うなデータに変換する処理のこと(構文解析とも)
抜き取りたいデータ
赤線で囲んだ部分
HTMLタグはspan
Class名はvalue
書いたコード(汚い)
Html_tagにspan
Tag_get(‘class’).pop(0)で入れた変数の中に含まれているか判定
Playtimeはclass名が違う
HTMLタグからClass名を取得するやり方以外にも、
データの検索・取得方法はある↓
正規表現
HTMLタグからClass名を取得するやり方のデメリット
・タグとクラス名が同じだけど要らない部分の情報も抜き出す
追加コード
Soup.get_text()でテキスト部分だけ抜き出せる
Text.find(‘ Play Time’)で検索
Re.findall(検索条件,検索する値)で取得します
なお正規表現を使うと汚くなりました
ちなみに
CSSセレクタを使うと特定のデータを直接的に取
り出せます
CSSセレクタって?
◦ CSSによるデザイン指定をどのHTML要素に適用さ
せるかを指定するのに用いられるもの
CSSセレクタの取得は→
Soup.select_one(cssセレクタ値)
CSSセレクタの値は↓
同じ要領でweaponsページも取得するよ!
タグはspan、クラス名はnameなので
先ほどのコードをほぼ流用できる!
HTMLファイルを構文解析しただけだと
スクレイピングしたデータ
取得したデータから分析用のデータセットにするには
数値化や前処理などが必要だよ!
スクレイピングで取得できるデータはあくまで文字列
なので
・文字列を正規表現で%や1,000の「,」の抜き取りをする
・文字列を数値へ変換し、プレイ時間を分換算したりする
・プレイヤー名も配列に入れる
・同値を削除したり、要らない文字を消すとか
様々な処理を行うする必要がある
なお取得したデータはデータベースに入れる必要もあるよ(私はMongoDBを使用)
数値化・DBへ
結果、一度CSV化したものをDFで表示
MongoDBにはこういった感じで入る
スクレイピングの注意点
スクレイピングは一度サーバーにリクエストを送るため、
高速かつ大量にリクエストを送るとサーバーダウンする可能性も
(事実上Dos攻撃と言えなくもない)
参考:岡崎市立中央図書館事件
スクレイピングする際には必ず時間間隔を十分に置いて
リクエストを送ろう!
※(十分な時間間隔はサーバーのスペック、バグなどに影響されます)
動的にデータが変わるサイトからデータを取得するには
Seleniumを使用する必要があるよ
Seleniumって?
・Webアプリケーションをテストするためのポータブルフレームワークである。
動的なサイトはJavascriptが絡む↓
ブラウザなどでプログラムを動作させないとデータ取得できない
実は一試合ごとの結果を取得しようとしたけど、
弾かれた(サーバー側から拒否されたっぽい?)のでやめました
一試合ごとの戦績結果が取得できない…
人力は嫌だが、弾かれた以上それしかない、
そうだOCR(光学文字認識)を使えば楽なんじゃね!?
ってことでオープンソースOCRである
tesseract君を使いました
(詳しくはググってね)
結果
う~n、いまいち精度がよろしくない
(人力確定の知らせ)
今後は
スクレイピングしたデータからプレイヤーを分析するよ
◦ 以下は一度分析してみたよ
◦ クラスター分析:前線突撃か後方支援か中途半端かのプレイスタイルが判明
◦ アソシエーション分析:メジャーな武器はよく使われる、あと日本兵の武器を好むプレイヤーもいた
また次回にデータ分析の結果の話をしようかと思います!
ご清聴ありがとうございました!
ソースコード
後日GitHubか自分のはてなサイトでも開設して、データをうpします

More Related Content

Featured

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
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

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...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Scraping with python from bf vtracker