Created
May 23, 2021 20:17
-
-
Save israel-dryer/355ce3951241ca61d3f6c7b593fc2f08 to your computer and use it in GitHub Desktop.
Request FedEx Shipping Status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def shipping_status(tracking_num): | |
"""Request shipment status via tracking number. | |
Args: | |
tracking_num (int): The FedEx tracking number assigned to the shipment. | |
""" | |
url = "https://www.fedex.com/trackingCal/track" | |
headers = { | |
'Host': 'www.fedex.com', | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', | |
'Accept': '*/*', | |
'Accept-Language': 'en-US,en;q=0.5', | |
'Accept-Encoding': 'gzip, deflate, br', | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'X-Requested-With': 'XMLHttpRequest', | |
'Origin': 'https://www.fedex.com', | |
'Connection': 'keep-alive', | |
'Referer': 'https://www.fedex.com/en-us/home.html', | |
} | |
payload = '''data=%7B%22TrackPackagesRequest%22%3A%7B%22appType%22%3A%22WTRK%22%2C%22appDeviceType%22%3A%22%22%2C%22supportHTML%22%3Atrue%2C%22supportCurrentLocation%22%3Atrue%2C%22uniqueKey%22%3A%22%22%2C%22processingParameters%22%3A%7B%7D%2C%22trackingInfoList%22%3A%5B%7B%22trackNumberInfo%22%3A%7B%22trackingNumber%22%3A%22{}%22%2C%22trackingQualifier%22%3A%22%22%2C%22trackingCarrier%22%3A%22%22%7D%7D%5D%7D%7D&action=trackpackages&locale=en_US&version=1&format=json''' | |
response = requests.post(url, headers=headers, data=payload.format(tracking_num)) | |
if response.status_code == 200: | |
return response.json() | |
if __name__ == '__main__': | |
tn = 940388682457 | |
status = shipping_status(tn) | |
print(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment