php - How to write curl get request on python to decrease parsing time -
i have basic curl request work site api in php:
$headers = array( "content-type: text/xml;charset=\"windows-1251\"", "host:api.content.com", "accept:*/*", "authorization:qwerty" ); $ch = curl_init(); curl_setopt($ch, curlopt_url,"https://api.content.com/v1.xml"); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_timeout, 60); curl_setopt($ch, curlopt_autoreferer, true); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_ssl_verifyhost, false); curl_setopt($ch, curlopt_ssl_verifypeer, false); $data = curl_exec($ch); $f = new simplexmlelement($data); #echo $data; $total = $f['total']; curl_close($ch); }
what best way write in python in case, request used in separate subprocesses decrease parsing time?
you can use requests, requests document;
>>> import json >>> url = 'https://api.github.com/some/endpoint' >>> payload = {'some': 'data'} >>> headers = {'content-type': 'application/json'} >>> r = requests.post(url, data=json.dumps(payload), headers=headers)
Comments
Post a Comment