作者areyo (没有名字的怪物)
看板Python
标题[问题] 请教正规表示法
时间Sun Jun 17 00:00:37 2012
大家晚安
小弟最近刚开始学正规式
但试了很多次,还是有点不太懂正规式
我今天要抓
http://www.lme.com/copper.asp 这网页里面表单里的价格(Cash)
我先看了一下它的source code,找到它的table的部份
去下了正规式,但都不能,有大大可以帮我看看是那边做错了
import re, urllib2
from HTMLParser import HTMLParser
gSellerPrice=[]
class MyHtml(HTMLParser):
def handle_data(self,data):
print data
gSellerPrice.append(data)
req=urllib2.Request("
http://www.lme.com/copper.asp")
f=urllib2.urlopen(req)
page=f.read()
html=MyHtml()
#print page
patten=r"\.Cash</strong>.+</tr>$" #ignore middle parts
match=re.search(patten,page,re.M) #flag = re.S means end with newline
print "Find",match
txt=match.group()
html.feed(txt)
html.close()
print "gSellerPrice:",gSellerPrice.pop(3)
谢谢
另个问题是,re.search()中带的re.S 跟re.M 是指排除换行吗??
--
『控制自己的慾望,认识自己的无知,做自己的主人』
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.127.191.91
1F:→ Jason1122:处理网页的话要不要试试看Beautiful Soup 06/19 01:47
2F:→ areyo:嗯好,我试看看,它能处理javascript吗? 06/19 14:23