Python Basic. Download python Go to and download Python 2.7.8.

Post on 05-Jan-2016

302 views 13 download

Transcript of Python Basic. Download python Go to and download Python 2.7.8.

Python Basic

Download pythonGo to www.python.org 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.

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

Ex1: Reading specific value from web

8. Open Python

9 . Go to

10 . Go to

11.Choose ‘File’ and ‘New File’

12. Edit code here

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']

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!

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

and click ‘Run Module’

Code & ouput

Code & output

Ex2: crawling web page(s) with key value

Type below for crawlinggoogle

Full code

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

output