定义为函数
from urllib.parse import urlencode
def get_url(viewlet, customer, currency):
params = {
'viewlet': viewlet,
'__parameters__': f'%7B%22__pi__%22%3Atrue%2C%22endcustomername%22%3A%22{customer}%22%2C%22rmbrate%22%3A%22M%20{currency}%22%7D',
}
base_url = 'http://fb.com/decision/view/form'
encode_params = urlencode(params)
url = f'{base_url}?{encode_params}'
print(url)
return url
viewlet = '%2FRevenue_PRD%2FRevenue_Reports_Seagate_all.frm'
customer = 'Oracle'
currency = 'RMB'
get_url(viewlet, customer, currency)
from urllib.parse import urlencode
url = "https://example.com/search"
params = {
"q": "python programming",
"page": 1,
"lang": "en"
}
encoded_params = urlencode(params)
query_url = f"{url}?{encoded_params}"
print(query_url)