[問題] 請教正規表示法
大家晚安
小弟最近剛開始學正規式
但試了很多次,還是有點不太懂正規式
我今天要抓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
→
06/19 01:47, , 1F
06/19 01:47, 1F
→
06/19 14:23, , 2F
06/19 14:23, 2F