[問題] 請教正規表示法

看板Python作者 (沒有名字的怪物)時間12年前 (2012/06/17 00:00), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
大家晚安 小弟最近剛開始學正規式 但試了很多次,還是有點不太懂正規式 我今天要抓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
處理網頁的話要不要試試看Beautiful Soup
06/19 01:47, 1F

06/19 14:23, , 2F
嗯好,我試看看,它能處理javascript嗎?
06/19 14:23, 2F
文章代碼(AID): #1FtAsepT (Python)