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

拜师贴:如何使用python抓取网页数据

如何使用python,将下面的网页
http://quotes.money.163.com/corp/1034/code=600221.html
那张资产负债表抓取出来,发到一个文本文件中?
请留下qq,我拜你为师


Python code:
import re
import urllib2

notePattern = '<table width="125" border="0" align="left" cellpadding="5" cellspacing="0" class="dataTb04">(?P<code>[\s\S]*?)</table>*?'

web = urllib2.urlopen("http://quotes.money.163.com/corp/1034/code=600221.html")
content = web.read()
p = re.compile(notePattern)
iter = p.finditer(content)
for matcher in iter:
code = matcher.group('code')
newpattern = '<td>(?P<data>[\s\S]*?)</td>'
s = re.compile(newpattern)
i = s.finditer(code)
for m in i:
d = m.group('data')
if d == '&nbsp;' or d =='&nbsp' or d == '&nbsp&nbsp;':
print ''
elif d.startswith('<font'):
f = '<font color=red>(?P<info>[\s\S]*?)</font>'
pf = re.compile(f)
t = pf.finditer(d)
for mm in t:
print mm.group('info')
else:
print d


沙老师,程序好像没有全部写完,可否简要介绍一下你的思考步骤,并将完整的程序贴出来?

这个表还算好,整个表结构比较清楚,
用beautiful


相关问答:

Python中的Unicode在Delphi如何还原成Gb2312?

已知Python 中:
s = unicode("测试", "gb2312")
s = u'\u6d4b\u8bd5'
print s
测试

在Delphi里面如何将\u6d4b\u8bd5这样的还原成Gb2312的汉字呢?
找到个方法
......

python怎么print 'hello world'

大家好,我是一个新手,刚开始学python,但是刚开始的helloworld都没法打印,让我很无奈。
我的python安装路径为f:\python31。在path中也设置对了,在windows下运行是这样显示的,希望各位前辈指点一下。谢谢
Pyth ......

boost.python c++嵌入python如何重载=?

我现在有一个需求是这样的
我有2个类
class A
{
public:
int val;
}

class B
{
public:
A a
}

现在在脚本中只能
b.a.val = 1
我在python中想使用
b.a = 1
......

python访问网页带cookie问题

我现在要用python访问一个网站的网页,取得一些信息
但是网站要求先登录,然后才能继续访问,登录过程就是写了个cookie
请问下python访问网页怎么保持住cookie呢?

我用的是python3.1,只有urllib和htt ......

开始学习python, 大家多多指点

刚刚买了一本《Python核心编程》,开始学习python。大家多多指教

电子书就很多。。。

《Python核心编程》这书的第一版还是不错的,第二版很不咋的,真的。

个人的意见是:初学用《Dive in Python》, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号