Submit Search
Upload
Python 爬蟲
•
Download as PPTX, PDF
•
2 likes
•
561 views
Andy Yao
Follow
北科程式設計研究社 - Python 應用入門(爬蟲)
Read less
Read more
Software
Report
Share
Report
Share
1 of 46
Download now
Recommended
蜘蛛
蜘蛛
thinkinlamp
99 botnet期末簡報
99 botnet期末簡報
Shi-Hwao Wang
99 第六屆國際健康資訊管理研討會簡報botnet
99 第六屆國際健康資訊管理研討會簡報botnet
Shi-Hwao Wang
Data Crawler using Python (I) | WeiYuan
Data Crawler using Python (I) | WeiYuan
Wei-Yuan Chang
data science homework
data science homework
Joey Cheng
Intro to Dialogflow Chatbot Development
Intro to Dialogflow Chatbot Development
Ryan Chung
1.[web security share]google_hacking
1.[web security share]google_hacking
Mike Ching
使用GoogleAppEngine建立个人信息中心
使用GoogleAppEngine建立个人信息中心
Du Yamin
Recommended
蜘蛛
蜘蛛
thinkinlamp
99 botnet期末簡報
99 botnet期末簡報
Shi-Hwao Wang
99 第六屆國際健康資訊管理研討會簡報botnet
99 第六屆國際健康資訊管理研討會簡報botnet
Shi-Hwao Wang
Data Crawler using Python (I) | WeiYuan
Data Crawler using Python (I) | WeiYuan
Wei-Yuan Chang
data science homework
data science homework
Joey Cheng
Intro to Dialogflow Chatbot Development
Intro to Dialogflow Chatbot Development
Ryan Chung
1.[web security share]google_hacking
1.[web security share]google_hacking
Mike Ching
使用GoogleAppEngine建立个人信息中心
使用GoogleAppEngine建立个人信息中心
Du Yamin
Web crawler - Scrapy
Web crawler - Scrapy
yafish
Python系列4
Python系列4
數真 蔡
京东商城Pop商品搜索原理
京东商城Pop商品搜索原理
changzhongzhong
專案分層架構 twMVC#18
專案分層架構 twMVC#18
twMVC
twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構
twMVC
Using google appengine_final
Using google appengine_final
Wei Sun
Seo
Seo
mornone
Seo实操手册
Seo实操手册
mornone
Javascript
Javascript
Ryan Chung
企业安全应急响应与渗透反击V0.04(程冲)
企业安全应急响应与渗透反击V0.04(程冲)
WASecurity
Py ladies 0928
Py ladies 0928
Chia-Yi Yen
Py ladies 0928
Py ladies 0928
Yen_CY
聊天機器人概論 Introduce to chat bot sevices
聊天機器人概論 Introduce to chat bot sevices
Duran Hsieh
Web scraping入門1
Web scraping入門1
兆欽 丘
開發實用創新的 Android 應用程式
開發實用創新的 Android 應用程式
建興 王
20151021联动技术大讲堂35(刘胜)网络爬虫技术实战
20151021联动技术大讲堂35(刘胜)网络爬虫技术实战
liu sheng
Servlet & JSP 教學手冊第二版 - 課後練習解答
Servlet & JSP 教學手冊第二版 - 課後練習解答
Justin Lin
42qu thrift1
42qu thrift1
Zoom Quiet
搜索引擎技术介绍
搜索引擎技术介绍
bigqiang zou
Html5开发android应用程序概述
Html5开发android应用程序概述
kevin_yanggl
More Related Content
Similar to Python 爬蟲
Web crawler - Scrapy
Web crawler - Scrapy
yafish
Python系列4
Python系列4
數真 蔡
京东商城Pop商品搜索原理
京东商城Pop商品搜索原理
changzhongzhong
專案分層架構 twMVC#18
專案分層架構 twMVC#18
twMVC
twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構
twMVC
Using google appengine_final
Using google appengine_final
Wei Sun
Seo
Seo
mornone
Seo实操手册
Seo实操手册
mornone
Javascript
Javascript
Ryan Chung
企业安全应急响应与渗透反击V0.04(程冲)
企业安全应急响应与渗透反击V0.04(程冲)
WASecurity
Py ladies 0928
Py ladies 0928
Chia-Yi Yen
Py ladies 0928
Py ladies 0928
Yen_CY
聊天機器人概論 Introduce to chat bot sevices
聊天機器人概論 Introduce to chat bot sevices
Duran Hsieh
Web scraping入門1
Web scraping入門1
兆欽 丘
開發實用創新的 Android 應用程式
開發實用創新的 Android 應用程式
建興 王
20151021联动技术大讲堂35(刘胜)网络爬虫技术实战
20151021联动技术大讲堂35(刘胜)网络爬虫技术实战
liu sheng
Servlet & JSP 教學手冊第二版 - 課後練習解答
Servlet & JSP 教學手冊第二版 - 課後練習解答
Justin Lin
42qu thrift1
42qu thrift1
Zoom Quiet
搜索引擎技术介绍
搜索引擎技术介绍
bigqiang zou
Html5开发android应用程序概述
Html5开发android应用程序概述
kevin_yanggl
Similar to Python 爬蟲
(20)
Web crawler - Scrapy
Web crawler - Scrapy
Python系列4
Python系列4
京东商城Pop商品搜索原理
京东商城Pop商品搜索原理
專案分層架構 twMVC#18
專案分層架構 twMVC#18
twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構
Using google appengine_final
Using google appengine_final
Seo
Seo
Seo实操手册
Seo实操手册
Javascript
Javascript
企业安全应急响应与渗透反击V0.04(程冲)
企业安全应急响应与渗透反击V0.04(程冲)
Py ladies 0928
Py ladies 0928
Py ladies 0928
Py ladies 0928
聊天機器人概論 Introduce to chat bot sevices
聊天機器人概論 Introduce to chat bot sevices
Web scraping入門1
Web scraping入門1
開發實用創新的 Android 應用程式
開發實用創新的 Android 應用程式
20151021联动技术大讲堂35(刘胜)网络爬虫技术实战
20151021联动技术大讲堂35(刘胜)网络爬虫技术实战
Servlet & JSP 教學手冊第二版 - 課後練習解答
Servlet & JSP 教學手冊第二版 - 課後練習解答
42qu thrift1
42qu thrift1
搜索引擎技术介绍
搜索引擎技术介绍
Html5开发android应用程序概述
Html5开发android应用程序概述
Python 爬蟲
1.
Python 網路爬蟲 1
2.
上週簡報 2 https://goo.gl/feHnfk
3.
ABOUT ME 姚韋辰 (黑楓) 北科大資工二 北科程式設計研究社
1st 社長 T.T.S. App 開發者 專長 Android App 開發 歡迎來加我臉書好友找我聊天~OωO 3
4.
什麼是網路爬蟲? 4
5.
網路爬蟲 5 自動快速抓取網路上的資料
6.
我們眼中的網站 6
7.
爬蟲眼中的網站 7
8.
網路如何運作的? 8
9.
兩個端點 客戶端 伺服器端 請求 (Request) 回應
(Response) 9
10.
兩個端點 客戶端 伺服器端 使用 HTTP
溝通 負責向伺服器端請求 (request) 資源, 並且將資源組合成頁面 呈現給使用者 負責回應 (response) 客戶端 的請求,根據請求回應相對應 的資源 10
11.
網頁構成 HTML:網頁的內容 CSS:網頁的外觀 JavaScript:網頁的行為 11
12.
CSS 選擇器 12 它能讓你選定你要的元素
13.
CSS 選擇器 13 class:類別 id:唯一識別碼 練習網站
14.
JavaScript 渲染 14
15.
經過渲染 15
16.
未渲染 16
17.
關閉 JavaScript 渲染工具 Quick
Javascript Switcher 17
18.
F12 開發人員工具 18 詳細介紹
19.
19
20.
物件 20 Python 中所有東西都是物件 物件.XXX() →
執行物件的動作 物件.xxx → 屬於物件的值
21.
模組與套件 21
22.
模組 (module) 簡單來說就是一個 Python
檔案 22
23.
套件 (package) 模組就是一個檔案,而套件就是一個目錄 簡單來說套件就是個模組庫 23
24.
懂得用套件,你的人生就會是彩色的.. 24
25.
PyPI 25 這是 Python 的第三方套件集中地 目前蒐集了超過五萬個的第三方套件
26.
Python的套件管理程式 - pip 26 Python
的套件管理工具 它集合下載、安裝、升級、管理、移除套件等功能 可透過 pip 下載 PyPl 的套件
27.
常用套件簡介 27
28.
網站框架套件 28 套件名稱 簡述 Django 完整而強大的
Web 框架 Pyramid 另一個完整強大的 web 框架 web2py Google app engine 預設使用的框架 flask 相較於前三個是輕量的網站框架
29.
圖片處理 29 套件名稱 簡述 Pillow 早先大家使用 PIL,但年久失修後,出 了一個
fork 的版本,就是 Pillow
30.
科學計算 30 套件名稱 簡述 Numpy 支援非常多的科學計算,包含矩陣運 算、線性代數、傅立葉轉換等。可說 是集大成者,大多數科學計算套件皆 有使用 Matplotlib 可以畫出各種圖型如長條圖、分佈圖、 立體圖等 pandas 提供特殊資料結構,具有數據處理和 資料分析的功能 scikit-learn 機器學習的套件,包含內建的分群分 類計算、回歸、統計等功能 TensorFlow 由
Google 開發的最新潮機器學習套件
31.
自然語言處理 31 套件名稱 簡述 nltk 理論基礎及功能很強大的語言處理套 件,但相對低階,需花一些時間熟悉 才能流利使用 textblob 較高階的分詞、分句、語言分析工具 jieba 針對中文的分詞、分句、語言分析工 具
32.
網路請求用戶端 32 套件名稱 簡述 requests 可以模擬各種網路請求,如:get、 post、put、delete等
33.
Requests 33 向網頁發送請求並接收回應
34.
Requests 用法 34 # 以
GET 的方式傳請求給目標網址,並傳回 Response 物件 requests.get('網址') # 以 POST 的方式傳請求給目標網址,並傳回 Response 物件 requests.post('網址') # 取得 Response 中的網頁原始碼 Response.text
35.
Requests 範例 35 import requests url
= 'https://www.ptt.cc/bbs/joke/index.html' # 向該網址發出 HTTP GET 請求,取得該網頁所有資訊,並存入 response response = requests.get(url) # 從 response 中取出的網頁原始碼的資訊,並印出 print(response.text)
36.
BeautifulSoup 36 用來分析與抓取 html 中的元素
37.
BeautifulSoup 用法 37 # 用
html.parser 分析 response.text,並存入 soup 中 soup = BeautifulSoup(response.text, 'html.parser') # 搜尋所有 html 中標籤為 div 且 class 為 r-ent 的目標 soup.findAll('標籤', 'class')
38.
BeautifulSoup 範例 38 import requests from
bs4 import BeautifulSoup url = 'https://www.ptt.cc/bbs/joke/index.html' response = requests.get(url) # 用 html.parser 分析 response.text,並存入 soup 中 soup = BeautifulSoup(response.text, 'html.parser') # 搜尋所有 html 中標籤為 div 且 class 為 r-ent 的目標 article = soup.findAll('div', 'r-ent') # 印出 article print(article)
39.
讓我們來爬 PTT 吧! 39
40.
步驟思路 40 1. 取得網頁程式碼 2. 選擇想要取得的資訊 3.
透過標籤、class、id 鎖定目標 4. 取出目標標籤 5. 取出所有目標內容
41.
1. 取得網頁程式碼 41 import requests url
= 'https://www.ptt.cc/bbs/joke/index.html' # 目標網址 response = requests.get(url) # 取得網頁資訊
42.
2. 選擇抓取目標 42
43.
3. 目標特徵 43 1. div
標籤 2. class 屬性為 r-ent
44.
4. 取出目標標籤 44 import requests from
bs4 import BeautifulSoup url = 'https://www.ptt.cc/bbs/joke/index.html' # 目標網址 # 取得網頁資訊 response = requests.get(url) # 使用 html.parser 解析剛取回的 response soup = BeautifulSoup(response.text, 'html.parser') # 取得所有符合的目標 articles = soup.find_all('div', 'r-ent') print(articles) # 印出標籤數量(文章數量)
45.
5. 取出所有目標內容 45 import requests from
bs4 import BeautifulSoup url = 'https://www.ptt.cc/bbs/joke/index.html' # 目標網址 NOT_EXIST = BeautifulSoup('<a href="">本文已被刪除</a>', 'html.parser').a # 當文章不存在時,以此代替原標籤 response = requests.get(url) # 取得網頁資訊 soup = BeautifulSoup(response.text, 'html.parser') # 使用 html.parser 解析剛取回的 response articles = soup.find_all('div', 'r-ent') # 取得所有目標標籤 print('共%d項結果:' % len(articles)) # 印出標籤數量(文章數量) for article in articles: meta = article.find('div', 'title').find('a') or NOT_EXIST # 如果文章以刪除,以預設內容替換 title = meta.get_text().strip() # 取得標題,並去除頭尾空格 link = meta.get('href') # 取得連結 date = article.find('div', 'date').get_text() # 取得日期 author = article.find('div', 'author').get_text() # 取得作者 print('{0} {1: <15} {2: <30} {3}'.format( date, author, title, 'https://www.ptt.cc/' + link))
46.
謝謝聆聽 46
Download now