For completing this we need to install curl_to_requests Once we install we are ready to go ... for Converting cURL commands into equivalent Python Requests code
below is the sample code of use:
import curl_to_requests
curl_cmd = """curl 'https://github.com/mosesschwartz/curl_to_requests' \-H 'Accept-Encoding: gzip, deflate, sdch' \-H 'Accept-Language: en-US,en;q=0.8' \-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36' \-H 'Accept: text/html, */*; q=0.01' \-H 'Referer: https://github.com/mosesschwartz/curl_to_requests' \-H 'Connection: keep-alive' --compressed"""
print curl_to_requests.curl_to_requests(curl_cmd)
Here is the sample output:
import requests
headers = {'Accept-Language': ' en-US,en;q=0.8', 'Accept-Encoding': ' gzip, deflate, sdch', 'Accept': ' text/html, */*; q=0.01', 'User-Agent': ' Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36', 'Connection': ' keep-alive', 'Referer': ' https'}
r = requests.GET('https://github.com/mosesschwartz/curl_to_requests', headers=headers)
This comment has been removed by the author.
ReplyDelete