python basic. download python go to and download python 2.7.8

18
Python Basic

Upload: karen-henderson

Post on 05-Jan-2016

342 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: Python Basic. Download python Go to  and download Python 2.7.8

Python Basic

Page 2: Python Basic. Download python Go to  and download Python 2.7.8

Download pythonGo to www.python.org and download Python 2.7.8

Page 3: Python Basic. Download python Go to  and download Python 2.7.8

Follow steps below

1. Search “phthon download” in google.2. Click https://www.python.org/downloads/.3. Download Python 2.7.8.4. Click “run”.5. Click “next” in below screen.

Page 4: Python Basic. Download python Go to  and download Python 2.7.8

6. Click “next “.7. Click “next” , and click “finish”.

Page 5: Python Basic. Download python Go to  and download Python 2.7.8

Ex1: Reading specific value from web

Page 6: Python Basic. Download python Go to  and download Python 2.7.8

8. Open Python

Page 7: Python Basic. Download python Go to  and download Python 2.7.8

9 . Go to

10 . Go to

Page 8: Python Basic. Download python Go to  and download Python 2.7.8

11.Choose ‘File’ and ‘New File’

Page 9: Python Basic. Download python Go to  and download Python 2.7.8

12. Edit code here

Page 10: Python Basic. Download python Go to  and download Python 2.7.8

13. Edit below code.import urllibimport rehtmlfile = urllib.urlopen("http://finance.yahoo.-com/q?s=AAPL")htmltext = htmlfile.read()regex = '<span id="yfs_l84_aapl">(.+?)</span>'pattern = re.compile(regex)price = re.findall(pattern, htmltext)print price

After you hit enter you can see the output below.['116.47']

Page 11: Python Basic. Download python Go to  and download Python 2.7.8

14. Go to and link “finance.yahoo.com” in chrome -> Block the value to be read and right click on the block-> Click “component search” -> Then, you can see the screen below. Copy the blocked code below!

Page 12: Python Basic. Download python Go to  and download Python 2.7.8

15. After coding is overrun program as below: choose ‘run’

and click ‘Run Module’

Page 13: Python Basic. Download python Go to  and download Python 2.7.8

Code & ouput

Page 14: Python Basic. Download python Go to  and download Python 2.7.8

Code & output

Page 15: Python Basic. Download python Go to  and download Python 2.7.8

Ex2: crawling web page(s) with key value

Page 16: Python Basic. Download python Go to  and download Python 2.7.8

Type below for crawlinggoogle

Page 17: Python Basic. Download python Go to  and download Python 2.7.8

Full code

# -*- coding:utf-8 -*-import urllib2url='http://www.google.co.kr'html=urllib2.urlopen(url).read()print(html)

Page 18: Python Basic. Download python Go to  and download Python 2.7.8

output