|
def askURL(url):
global html
request = urllib.request.Request(url)#发送请求
try:
resp**e = urllib.request.urlopen(request)#取得响应
html= resp**e.read()#获取网页内容
# print (html)
except urllib.error.URLError as e:
if hasattr(e,"code"):
print (e.code)
if hasattr(e,"reason"):
print (e.reason)
return html
NameError: name 'html' is not defined 一开始的代码没有global html这行,报错是UnboundLocalError: local variable 'html' referenced before assignment加了全局变量后又变成这样了
|
|