[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
#! /usr/bin/python # -*- coding: utf-8 -*- import urllib import sgmllib import re class Stripper(sgmllib.SGMLParser): def __init__(self): sgmllib.SGMLParser.__init__(self) def strip(self, some_html): self.theString = "" self.feed(some_html) self.close() return self.theString def handle_data(self, data): self.theString += data some_url='http://stocks.finance.yahoo.co.jp/stocks/detail/?code=****.o' filehandle = urllib.urlopen(some_url, proxies={}) data = Stripper().strip(filehandle.read()) regex=re.compile('20分ディレイ株価(.*)', re.I) price = 0 for line in data.split('\n'): result=regex.findall(line) if len(result)>0: price = result[0] print price