ÄÚÈÝ·¢²¼¸üÐÂʱ¼ä : 2025/1/9 11:10:57ÐÇÆÚÒ» ÏÂÃæÊÇÎÄÕµÄÈ«²¿ÄÚÈÝÇëÈÏÕæÔĶÁ¡£
eoLinker-API Shop Ц»°´óÈ« Pythonµ÷ÓÃʾÀý´úÂë
Ц»°´óÈ«
×îС¢×ʱµÄЦ»°¶Î×Ó¡£ ¸Ã²úÆ·ÓµÓÐÒÔÏÂAPIs£º 1. Ëæ»ú»ñȡЦ»° 2. ˳Ðò»ñȡЦ»°
×¢Ò⣬¸ÃʾÀý´úÂë½öÊÊÓÃÓÚ www.apishop.net ÍøÕ¾ÏÂAPI ʹÓøòúÆ·Ç°£¬ÄúÐèҪͨ¹ý https://www.apishop.net/#/api/detail/?productID=122 ÉêÇëAPI·þÎñ
1.Ëæ»ú»ñȡЦ»°
#!/usr/bin/env python # -*- coding: utf-8 -*- # ²âÊÔ»·¾³: python2.7
# °²×°requestsÒÀÀµ => pip install requests/ easy_install requests
# µ¼ÈërequestsÒÀÀµ import requests import json import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def apishop_send_request(method, url, params=None, headers=None): '''
ת·¢ÇëÇóµ½Ä¿µÄÖ÷»ú
@param method str ÇëÇó·½·¨ @param url str ÇëÇóµØÖ·
@param params dict ÇëÇó²ÎÊý @param headers dict ÇëÇóÍ· '''
method = str.upper(method) if method == 'POST':
return requests.post(url=url, data=params, headers=headers) elif method == 'GET':
return requests.get(url=url, params=params, headers=headers) else:
return None
method = \
url = \ headers = None
params = {
\ÐèÒª´Ówww.apishop.net»ñÈ¡ \»ñÈ¡ÌõÊý£¨×î´ó20£© }
result = apishop_send_request(method=method, url=url, params=params, headers=headers) if result:
body = result.text
response = json.loads(body)
status_code = response[\ if (status_code == '000000'): # ״̬ÂëΪ000000, ˵Ã÷ÇëÇó³É¹¦ print('ÇëÇó³É¹¦£º%s' % (body,)) else:
# ״̬Âë·Ç000000, ˵Ã÷ÇëÇóʧ°Ü print('ÇëÇóʧ°Ü: %s' % (body,)) else:
# ·µ»ØÄÚÈÝÒì³££¬·¢ËÍÇëÇóʧ°Ü print('·¢ËÍÇëÇóʧ°Ü')
2.˳Ðò»ñȡЦ»°
#!/usr/bin/env python # -*- coding: utf-8 -*- # ²âÊÔ»·¾³: python2.7
# °²×°requestsÒÀÀµ => pip install requests/ easy_install requests
# µ¼ÈërequestsÒÀÀµ import requests import json import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def apishop_send_request(method, url, params=None, headers=None): '''
ת·¢ÇëÇóµ½Ä¿µÄÖ÷»ú
@param method str ÇëÇó·½·¨ @param url str ÇëÇóµØÖ·
@param params dict ÇëÇó²ÎÊý @param headers dict ÇëÇóÍ·
'''
method = str.upper(method) if method == 'POST':
return requests.post(url=url, data=params, headers=headers) elif method == 'GET':
return requests.get(url=url, params=params, headers=headers) else:
return None
method = \
url = \ headers = None
params = {
\ÐèÒª´Ówww.apishop.net»ñÈ¡ \Ò³Â룬ĬÈϵÚÒ»Ò³
\ÿҳÌõÊý£¨×î´ó20£©
\¸üÐÂʱ¼ä£¨²»Ìî´Ó×îÔçµÄÊý¾Ý¿ªÊ¼£©£¬Ê±¼ä¸ñʽ¡°2017-08-31 00:00:00¡±
\Êý¾ÝµÄ¸üÐÂÈÕÆÚÏà¶ÔÓÚupdateTime£¨1£ºbefore[֮ǰ]£¬2£ºafter[Ö®ºó]£© }
result = apishop_send_request(method=method, url=url, params=params, headers=headers) if result:
body = result.text
response = json.loads(body)
status_code = response[\ if (status_code == '000000'): # ״̬ÂëΪ000000, ˵Ã÷ÇëÇó³É¹¦ print('ÇëÇó³É¹¦£º%s' % (body,)) else:
# ״̬Âë·Ç000000, ˵Ã÷ÇëÇóʧ°Ü print('ÇëÇóʧ°Ü: %s' % (body,)) else:
# ·µ»ØÄÚÈÝÒì³££¬·¢ËÍÇëÇóʧ°Ü print('·¢ËÍÇëÇóʧ°Ü')