Python简易股票查询(抓取google财经的内容)
看着网上抓取网页数据的文章直瞪眼
后来想到用字符串分割来提取相应部分的内容
程序简单,但数行数和下标费了很长时间
我知道这肯定不是最好的办法- -!!
但我实现了,哈哈
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
baseurl="http://www.google.cn/finance?q=SHA%3A"
stockNo=raw_input("请输入股票代码:")
fullUrl=baseurl+stockNo
#print fullUrl
stockPage=urlopen(fullUrl)
pageInfo=stockPage.readlines()
stockNameLine=pageInfo[4]
stockNameList=re.split('[ >]',stockNameLine)
print "您所查询的股票是:"+stockNameList[1]
stockInfoLine=pageInfo[184]
stockInfoList=re.split('values',stockInfoLine)
stockInfoDetail=re.split('"',stockInfoList[1])
print "现价:"+stockInfoDetail[3]
print "涨幅: "+stockInfoDetail[5]+"%"
print "每股收益: "+stockInfoDetail[9]
print "市值: "+stockInfoDetail[11]
chengJiaoLiang=re.split('[><]',pageInfo[248])
print "成交量: "+chengJiaoLiang[2]
while True:
stockSearch()
相关文档:
俄罗斯方块游戏,使用Python实现,总共有350+行代码,实现了俄罗斯方块游戏的基本功能,同时会记录所花费时间,消去的总行数,所得的总分,还包括一个排行榜,可以查看最高记录。
排行榜中包含一系列的统计功能,如单位时间消去的行数,单位时间得分等。
附源码:
from Tkinter import *
from tkMessageBox import *
i ......
凑24是经典的益智游戏,多玩可以使脑筋灵活一点,但是当遇到无解的时候,就会很伤脑筋,为此,写个程序来代为计算。
运行结果,去除了重复的一些表达式:
entry: 1
entry: 4
entry: 5
entry: 6
(4/(1-(5/6))) = 24
(6/((5/4)-1)) = 24
Press any key to exit...
entry: 3
entry: 3
entry: 8
entry: 8
(8/(3-(8 ......
原文出处:http://www.amk.ca/python/howto/regex/
原文作者:A.M. Kuchling (amk@amk.ca)
授权许可:创作共享协议
翻译人员:FireHare
校对人员:Leal
适用版本:Python 1.5 及后续版本
简介
Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式。Python 1.5之前版本则是通过 regex
模块提供 ......
1。
myCoolVariable="some_string"
os.system("echo myCoolVariable")
2.
>>> os.system('echo "asdg"')
asdg
0
>>> os.system("echo 'asdgwere'")
asdgwere
0
3.
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
potato
0
......
今天学习了一下Python的操作符重载,总结了几点比较神奇的东东:
------------------------------------------------------------------------------------------------------------
关于iter:
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......