2012-09-04 31 views
0

因爲我有一個腳本,使用了很多http請求,我決定創建一個函數來做到這一點(而不是有相同的代碼塊,並通過... )。但即時通訊面臨的問題是,我可以如何將file_a.py的html輸出返回到file_b.py?因爲我需要輸出來解析一些結果?使用http請求輸出var從函數到其他腳本

file_a.py

def invokeServer(proxyUser,proxyPass,proxyHost,iserver,isService,login,password): 

    proxy_auth = "http://"+proxyUser+":"+proxyPass+"@"+proxyHost 
    proxy_handler = urllib2.ProxyHandler({"http": proxy_auth}) 
    opener = urllib2.build_opener(proxy_handler) 
    opener = urllib2.build_opener() 
    urllib2.install_opener(opener) 
    request = urllib2.Request("http://"+iserver+""+isService) 
    base64string = base64.encodestring('%s:%s' % (login, password)).replace('\n', '') 
    request.add_header("Authorization", "Basic %s" % base64string) 
    response = urllib2.urlopen(request) 
    html= response.read() 
    return html 

file_b.py

from file_a import invokeServer 
invokeServer(proxyUser,proxyPass,proxyHost,iserver,isService,login,password) 

# From this line bellow, i need to use the html result from file_a.py 
doc = LH.fromstring(html) 
LE.strip_tags(doc,'b') 
data_list = doc.xpath("//td[text()='triggerNameList']/following-sibling::*")[0] 
triggerName = data_list.xpath("//td[text()='triggerName']/following-sibling::*/text()") 

在此先感謝。

回答

1

它存儲在一個變量:

html = invokeServer(... 
+0

哦..多麼愚蠢的我... 非常感謝=) –

相關問題