[問題] 關於回傳值

看板Python作者 (小B)時間15年前 (2010/09/12 22:37), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/1
我從另一個網頁傳url,name,key,gRule 可是,我的gRule並不是收到的那個涵數要用的 而是httpparser要用的 程式碼如下: --- class parseLinks(HTMLParser.HTMLParser): def handle_starttag(self, tag, attrs): if tag == 'a': for name,value in attrs: if name == 'href': result = re.search("catitemid=",value) if result is None: break else: print value print " " def webparser(request): if (request.has_key("url") and request.has_key("content") and request.has_key("key") and request.has_key("gRule")): if (request.POST["url"]=="" or request.POST["content"]=="" or request.POST["key"]=="" or request.POST["gRule"]==""): return render_to_response('parser.html') else: a=request.POST["url"] lParser = parseLinks() lParser.feed(urllib.urlopen(a).read()) lParser.close() return render_to_response('parser.html') --- result = re.search("cartitemid=",value) 裡面的cartitemid其實是webparser函數裡面收到的值 request.POST["gRule"] 可是,我不知道該怎麼把函數收到的這個值,送到httpparser裡面 讓他變成使用者輸入的方向(我現在是寫死的) 請問有人會嗎>"< 請教一下,謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.172.216.17

09/12 22:46, , 1F
httpparser __init__(self)裡面加個 myinput=[]
09/12 22:46, 1F

09/12 22:47, , 2F
外面可以用 實體.myinput 的方式去存取值
09/12 22:47, 2F
謝謝你:D 我用你的方法有成功^^* ※ 編輯: mirror012020 來自: 218.172.216.17 (09/13 01:01)
文章代碼(AID): #1CZEN6kz (Python)
文章代碼(AID): #1CZEN6kz (Python)