Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
我的PYTHON爬蟲編年史
Search
bingroom
January 09, 2019
Programming
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
我的PYTHON爬蟲編年史
Invited talk in Python Hsinchu User Group
bingroom
January 09, 2019
More Decks by bingroom
See All by bingroom
我如何在PyCon找到乾爹 ─ 工人智慧的展現
bingroom
0
260
厲害了,我的蟲 - 我在iii的爬蟲人生
bingroom
0
530
Other Decks in Programming
See All in Programming
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
110
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.1k
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
900
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
410
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
Git: the NoSQL Database
bkeepers
PRO
433
67k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
For a Future-Friendly Web
brad_frost
184
10k
Site-Speed That Sticks
csswizardry
13
1.6k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
A better future with KSS
kneath
240
18k
Transcript
౯ጱPYTHON粖恝翥ଙݥ Bingroom
About Me • Data engineer in • Comprehending DevOps •
Addiction to and
None
C# PHP JAVA Python窕 أ㭏ၹ
Python窕 أ㭏ၹ
None
None
History Events
History Events Mechanize Selenium + Tkinter Web API PyQuery
Outline • Mechanize: web automation • Selenium (with Tkinter): build
a tool to load dynamic content • Web API: find it, use it • PyQuery: fast crawler prototyping
Challenge 1: PTT
The Soup Everyone Loves
The Soup Everyone Loves
The Soup Everyone Loves
import mechanize
import mechanize
None
None
None
None
None
None
None
import mechanize Only in Python2
Python3: mechanicalsoup
Missing part in mechanicalsoup https://findbiz.nat.gov.tw/fts/query/QueryBar/queryInit.do
Missing part in mechanicalsoup
Missing part in mechanicalsoup
Challenge 2: Facebook Personal IDs
Personal ID?
Personal ID: OK
How to query personal pages?
How to query personal pages? By Facebook ’s Vulnerability
How to deal with AJAX?
How to deal with AJAX? Selenium: for loading dynamic content
PhantomJS: headless browser
PhantomJS: headless browser Headless Chrome
PIL: crop reCAPTCHA
PhantomJS: headless browser Headless Chrome PIL: crop reCAPTCHA Tkinter: GUI
design
PhantomJS: headless browser Headless Chrome cx_Freeze: everything to executable PIL:
crop reCAPTCHA Tkinter: GUI design
Good Game
Challenge 3: 22 Government Official Sites
News & Attachment 岄玖૱(tpe)物https://health.gov.taipei/Default.aspx?tabid=36&mid=442 岄Ӿ૱(txg)物 http://www.health.taichung.gov.tw/26216/26204/26216/26204/26201/26204/27056/Lpsimplelist चᵇ૱(klu)物 http://www.klchb.gov.tw/ch/news/newspaper/list.aspx?c0=640 岄ܖ૱(tnn)物 https://health.tainan.gov.tw/list.asp?nsub=A0A600&topage=1
ṛᵜ૱(khh)物 http://khd.kcg.gov.tw/Main.aspx?sn=398 碝玖૱(ntpe)物 http://www.health.ntpc.gov.tw 葦翻(ilc)物 http://www.ilshb.gov.tw/index.php?catid=23&cid=4 ໘瑼૱(tyc)物 http://dph.tycg.gov.tw/home.jsp?id=13 ࡱ嬝૱(cyi)物 https://www.cichb.gov.tw/news/indexpda.asp 碝ᒓ翻(hsh)物 http://www.hcshb.gov.tw/home.jsp?mserno=200802220002&serno=200802220015&menudata=HcshbMenu& 碝ᒓ૱(hsc)物 http://www.hccg.gov.tw/MunicipalNews?websitedn=ou=hcchb,ou=ap_root,o=hccg,c=tw&language=chinese 舏礣翻(mal)物 https://www.mlshb.gov.tw/tc/PressRelease.aspx?pn=1&department=7 ܖಭ翻(nto)物 http://www.ntshb.gov.tw/Default.aspx 玕翻(cwh)物 http://www.chshb.gov.tw/news/?type_id=127&top=0 襇翻(yun)物 http://www.ylshb.gov.tw/news/index.php?m=9&m1=14&m2=35 ࡱ嬝翻(chy)物 https://cyshb.cyhg.gov.tw/News.aspx?n=E236E03D6AE796F8&sms=A55ECAF6D99EACF8 䩚翻(pch)物 http://www.ptshb.gov.tw/News.aspx?CategorySN=1894&n=CC774672B906BC5E 臺荳翻(hwa)物 http://www.hlshb.gov.tw/files/40-1006-27-1.php 岄䩚翻(ttt)物 http://www.ttshb.gov.tw/files/40-1000-12-1.php?Lang=zh-tw ᰂ槹翻(kmn)物 http://phb.kinmen.gov.tw/News.aspx?n=87FB8DD4C759A8B5&sms=A2C62D68901B977C ᄯ竝翻(peh)物 https://www.phchb.gov.tw/home.jsp?id=23 蝫翻(lnn)物 http://www.matsuhb.gov.tw/2009web/news/news_contents.php?room=news1
News & Attachment 岄玖૱(tpe)物https://health.gov.taipei/Default.aspx?tabid=36&mid=442 岄Ӿ૱(txg)物 http://www.health.taichung.gov.tw/26216/26204/26216/26204/26201/26204/27056/Lpsimplelist चᵇ૱(klu)物 http://www.klchb.gov.tw/ch/news/newspaper/list.aspx?c0=640 岄ܖ૱(tnn)物 https://health.tainan.gov.tw/list.asp?nsub=A0A600&topage=1
ṛᵜ૱(khh)物 http://khd.kcg.gov.tw/Main.aspx?sn=398 碝玖૱(ntpe)物 http://www.health.ntpc.gov.tw 葦翻(ilc)物 http://www.ilshb.gov.tw/index.php?catid=23&cid=4 ໘瑼૱(tyc)物 http://dph.tycg.gov.tw/home.jsp?id=13 ࡱ嬝૱(cyi)物 https://www.cichb.gov.tw/news/indexpda.asp 碝ᒓ翻(hsh)物 http://www.hcshb.gov.tw/home.jsp?mserno=200802220002&serno=200802220015&menudata=HcshbMenu& 碝ᒓ૱(hsc)物 http://www.hccg.gov.tw/MunicipalNews?websitedn=ou=hcchb,ou=ap_root,o=hccg,c=tw&language=chinese 舏礣翻(mal)物 https://www.mlshb.gov.tw/tc/PressRelease.aspx?pn=1&department=7 ܖಭ翻(nto)物 http://www.ntshb.gov.tw/Default.aspx 玕翻(cwh)物 http://www.chshb.gov.tw/news/?type_id=127&top=0 襇翻(yun)物 http://www.ylshb.gov.tw/news/index.php?m=9&m1=14&m2=35 ࡱ嬝翻(chy)物 https://cyshb.cyhg.gov.tw/News.aspx?n=E236E03D6AE796F8&sms=A55ECAF6D99EACF8 䩚翻(pch)物 http://www.ptshb.gov.tw/News.aspx?CategorySN=1894&n=CC774672B906BC5E 臺荳翻(hwa)物 http://www.hlshb.gov.tw/files/40-1006-27-1.php 岄䩚翻(ttt)物 http://www.ttshb.gov.tw/files/40-1000-12-1.php?Lang=zh-tw ᰂ槹翻(kmn)物 http://phb.kinmen.gov.tw/News.aspx?n=87FB8DD4C759A8B5&sms=A2C62D68901B977C ᄯ竝翻(peh)物 https://www.phchb.gov.tw/home.jsp?id=23 蝫翻(lnn)物 http://www.matsuhb.gov.tw/2009web/news/news_contents.php?room=news1
https://aji.tw/slides/pycon2017
https://aji.tw/slides/pycon2017
PyQuery == jQuery • parent element > child element •
# for id • . for class • . when a class name has space (i.e. has 2 classes)
None
#table_0 > tbody > tr:nth-child(1) > td.CCMS_jGridView_td_Class_1 Chrome Inspector
Firefox Inspector (Firebug) #table_0 > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)
None
Usage (1) Generate DOM object by URL opener
Usage (2) Traverse elements and list target items
Usage (2) Traverse elements and list target items
Usage (3) Laugh.
Usage (3) Laugh. #table_0 > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)
( ) td ጱ ᒫԫ㮆 ጱ text
Usage (3) Laugh. #table_0 > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)
( ) td ጱ ᒫԫ㮆 a ጱ 痀 href
Usage (3) Laugh.
Beautifulsoup V.S. PyQuery
Preparation for timeout issue
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn)
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) Ӟ෭玖ṛ
䌃ਠᵍॠፗ矑硬粚 岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi)
碝ᒓ翻(hsh) 碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn)
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) encoding=Big5
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) Date አ࿆㾴ଙ
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) 猂硬አ࿆㾴ଙ
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) ֦磪ݣ傀㰷独㻟牫 猂硬አ࿆㾴ଙ
岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh)
碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) / 22 https://github.com/bingroom/city-health-news-TW
https://github.com/bingroom/city-health-news-TW 8 / 22 FAILED: 岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh)
碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi) 碝ᒓ翻(hsh) 碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn)
https://github.com/bingroom/city-health-news-TW 岄玖૱(tpe) 岄Ӿ૱(txg) चᵇ૱(klu) 岄ܖ૱(tnn) ṛᵜ૱(khh) 碝玖૱(ntpe) 葦翻(ilc) ໘瑼૱(tyc) ࡱ嬝૱(cyi)
碝ᒓ翻(hsh) 碝ᒓ૱(hsc) 舏礣翻(mal) ܖಭ翻(nto) 玕翻(cwh) 襇翻(yun) ࡱ嬝翻(chy) 䩚翻(pch) 臺荳翻(hwa) 岄䩚翻(ttt) ᰂ槹翻(kmn) ᄯ竝翻(peh) 蝫翻(lnn) 22 / 22 Successful:
Challenge 4: Hack Nielsen DAR System
How to get API from a website?
• Guess How to get API from a website?
How to get API from a website? • Guess
• Guess • Inspect How to get API from a
website?
• Guess • Inspect How to get API from a
website?
• Guess • Inspect How to get API from a
website?
Nielsen DAR Ad
Nielsen DAR Ad • Login by mechanize
Nielsen DAR Ad • Hold the header
Nielsen DAR Ad • Enjoy(?) the API
• Facebook • Gmail Inbox • Dcard • PChome Graph
API Multiprocess OAuth2.0 Xml base64 JSON regex random UA Keyword for Web APIs
Summary • Mechanize • BeautifulSoup • Selenium + Phantomjs •
APIs Less documentation Less limitation • Mechanicalsoup • PyQuery • Selenium + Chromedriver • APIs More documentation More limitation Past Now
None
PTT GOV websites Pchome Dcard Facebook Almost everything!
PTT GOV websites Pchome Dcard Facebook Almost everything!
Sikuli: PTT Crawler
Sikuli: Game Farming
Thanks for your listening! httpstatusdogs.com