易截截图软件、单文件、免安装、纯绿色、仅160KB

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抓取和解析网页(上)

对搜索引擎、文件索引、文档转换、数据检索、站点备份或迁移等应用程序来说,经常用到对网页(即HTML文件)的解析处理。事实上,通过Python语言提供的各种模块,我们无需借助Web服务器

者Web浏览器就能够解析和处理HTML文档。本文将详细介绍如何利用Python抓取和解析网页。首先,我们介绍一个可以帮助简化打开位于本地和 ......

我的VIM配置(ubuntu+python)

1,不用修改/etc/vim下的vimrc及gvimrc文件 。。。
      2,在~目录下,新建一个.vimrc的配置文件。内容如下:(高亮,自动对齐,自动缩进,显示行号)
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2006 Nov ......

Python中执行shell命令的实例

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重载学习手记

今天学习了一下Python的操作符重载,总结了几点比较神奇的东东:
------------------------------------------------------------------------------------------------------------
关于iter:
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......

python中os.path.dirname(__file__)的使用

     (1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如:
             python d:\pythonSrc\test\test.py
         &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号