Mais conteúdo relacionado
Semelhante a 電腦不只會幫你選土豆,還會幫你選新聞 (20)
電腦不只會幫你選土豆,還會幫你選新聞
- 2. About Me
• Andy (andy@dorm7.com)
• Taipei.py、PyCon TW、PyCon APAC ⼯工作⼈人員
• Backend Developer @ Dorm7 Software
• 平常都在寫 Python、Django
2
- 8. If I had an hour to solve a
problem I'd spend 55 minutes
thinking about the problem and 5
minutes thinking about solutions.
!
— Albert Einstein
8
- 21. Requests: HTTP for Humans
import requests!
!
def get_content(url):!
response = requests.get(url)!
return response.content!
19
- 22. Selenium - Web Browser
Automation
20
from selenium import webdriver!
!
browser = webdriver.Firefox()!
browser.get('http://www.google.com')!
- 23. Beautiful Soup: Navigating,
searching your html
from bs4 import BeautifulSoup!
!
soup = BeautifulSoup(html_content)!
soup.title!
soup.findAll('a')!
soup.find('div', {'id': 'summary'})!
21
- 27. readability - Pulls out main
body
from readability.readability
import Document!
!
doc = Document(content)!
print doc.summary()!
23
- 30. PyMongo
from pymongo import MongoClient!
!
client = MongoClient()!
db = client['news_database']!
news = db.news!
news.insert(data)!
news.find_one({'url': a['href']})!
26
- 53. 屏東/ 科技/ ⼤大學/ 裴家騏/ ⽼老師/ 團隊
/ 在/ 苗栗/ 的/ 研究/ 顯⽰示/ ,/ 近幾年
/ 來/ ,/ 無論/ 地⽅方/ 政府/ 或/ 私⼈人/
的/ 開發/ ,/ 都/ 使得/ ⽯石⻁虎/ 的/ 棲地
/ 不斷/ 地/ 減少/ 和/ 破碎/ 化/ 。/
斷詞
43
- 54. import jieba!
segs = jieba.cut(!
u”屏東科技⼤大學裴家騏⽼老師團隊在苗栗的研究顯⽰示"!
)!
print '/'.join(segs)!
jieba - 斷詞
屏東/ 科技/ ⼤大學/ 裴家騏/ ⽼老師/ 團隊/
在/ 苗栗/ 的/ 研究/ 顯⽰示/
44
- 64. Machine Learning is Simple
54
from sklearn import svm!
X, y = get_training_set()!
clf = svm.SVC()!
clf.fit(X, y)!
clf.predict(unknown)!
- 67. 今天沒提到但是可能有⽤用的
Packages
• Scrapy - 抓網⾴頁
• NLTK - ⾃自然語⾔言處理
• Pandas - Python Data Analysis Library
• Orange - Open source data visualization and
analysis
• Matplotlib - 畫圖
57