# GET方法访问网页# 格式:名称1=值1 & 名称2=值2 & 名称3=值3import urllib.parse
import urllib.request
url ="http://127.0.0.1:5000"try:
province = urllib.parse.quote("广东")# 对广东进行编码,编码成utf-8
city = urllib.parse.quote("深圳")
data ="province="+province+"&city="+city
html = urllib.request.urlopen("http://127.0.0.1:5000?"+data)
html = html.read()
html = html.decode()print(html)except Exception as err:print(err)
serve.py
import flask
app = flask.Flask(__name__)@app.route("/")defindex():try:
province = flask.request.args.get("province")if"province"in flask.request.args else""#服务器获取GET发送的数据
city = flask.request.args.get("city")if"city"in flask.request.args else""#如果没有省份城市,则返回空 会更加稳定return province+","+city
except Exception as err:returnstr(err)if __name__=="__main__":
app.run()