Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将http请求输出变量从函数转换为其他脚本_Python_Function - Fatal编程技术网

Python 将http请求输出变量从函数转换为其他脚本

Python 将http请求输出变量从函数转换为其他脚本,python,function,Python,Function,因为我有一个使用大量http请求的脚本,所以我决定创建一个函数来实现这一点(而不是一遍又一遍地使用相同的代码块…)。但我面临的问题是,如何将html输出从文件_a.py返回到文件_b.py?因为我需要输出来解析一些结果 文件a.py def invokeServer(proxyUser,proxyPass,proxyHost,iserver,isService,login,password): proxy_auth = "http://"+proxyUser+":"+proxyPass+"

因为我有一个使用大量http请求的脚本,所以我决定创建一个函数来实现这一点(而不是一遍又一遍地使用相同的代码块…)。但我面临的问题是,如何将html输出从文件_a.py返回到文件_b.py?因为我需要输出来解析一些结果

文件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
文件_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()")

提前感谢。

将其存储在变量中:

html = invokeServer(...