Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter 2(textual data: Every string has its place)、Exercise(p.57)を解いてみる。
Exercise(p.57)
コード(BBEdit)
sample57.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- import urllib.request page = urllib.request.urlopen( 'http://beans-r-us.appspot.com/prices-loyalty.html') text = page.read().decode('utf8') i = text.find('>$') if i != -1: price = text[i+2:i+6] print(price)
入出力結果(Terminal)
$ ./sample57.py 4.61 $
0 コメント:
コメントを投稿