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()
相关文档:
凑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 ......
在一个项目中需要获取随机数,谁知道遇到点问题:随机数不随机。所以我写了个简单原型。看下到底是啥问题。
import os,random,sys,time
while True:
father = os.fork()
if father:
time.sleep(2)
rd = 7
else:
#random.seed()
rd = random.choice([2,3,4,5])
......
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
......
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如:
python d:\pythonSrc\test\test.py
&nb ......
python_复杂数据类型
python中原生的队列有2种,一种是普通的队列(Queue),一种叫做优先队列(PriorityQueue),即小的先出列。
注意:队列是线程安全的,python 3.0中支持多进程,也有类似的Queue,但不是这个。
1栈、队列、堆
python中原生的队列有2种,一种是普通的队列(Queue),一种叫做优先队列(PriorityQueu ......