拜师贴:如何使用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 == ' ' or d ==' ' or d == '  ':
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
相关问答:
像 C 的 scanf() 那样
比如读入 1 2 3 a b c
每次读入一个
下面这个应该是你想要的吧:
Python code:
>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> ......
我每次上传的文件读到的数据都不正确。2M 的图片读得10多K 。。哪位大侠可以帮帮我啊。
#!D:\ProgrammerTools\python26\python.exe
#encoding=utf-8
import cgitb
import os
cgitb.enable()
import cgi,urllib ......
有一个文本 test.txt 里边全是数据,排列格式化如下:
1 2 3
4 5 6
7 8 9
怎么用python读取该文本并将每行三个数字相加,最后以文本 out.txt 输出结果,比如:
1+2+3=6
4+5+6=15
......
>>> x=-1
>>> if x>0:
print ('11')
>>> else:
SyntaxError: invalid syntax (<pyshell#20>, line 1)
网上搜的也是:
>>> x=int(input("Please ent ......
刚刚买了一本《Python核心编程》,开始学习python。大家多多指教
电子书就很多。。。
《Python核心编程》这书的第一版还是不错的,第二版很不咋的,真的。
个人的意见是:初学用《Dive in Python》, ......