Skip to content

Instantly share code, notes, and snippets.

@jdimpson
Last active May 6, 2022 19:09
Show Gist options
  • Save jdimpson/5588ffe077a8fe38ae62f081d05b1778 to your computer and use it in GitHub Desktop.
Save jdimpson/5588ffe077a8fe38ae62f081d05b1778 to your computer and use it in GitHub Desktop.
Python requests snippet to download a Wegmans recipe
#!/usr/bin/env python3
# Basic gist to download a dang recipe from Wegmans grocery store,
# hardcoded for https://shop.wegmans.com/recipes/3883/black-bean-enchiladas
# I used a fresh firefox instance so while these cookies probably contain unique/identifying information,
# they aren't representative of me.
# If you've used their site, you know how customer-hostile it is, and if you are into cooking, you've been
# frustrated by an inability to just "save-as" their recipes. The actually put the recipes ingredients and directions in
# an API, so this code accesses that.
# This is initial, no idea if any of the state data in the cookies or headers will time out, nor how much of it is dependent
# on the specific recipe. Please feel free to experiment and share your results, but I won't be updating this gist.
# If I end up spending more time on this, I'll make a proper repo for it.
# To create this, I dug through Firefox's web developer Network console, foudn the API call, exported it as a curl command,
# then converted to Python requests using https://curlconverter.com/
import requests
cookies = {
'_dd_s': 'rum=1&id=fc1a0a3f-68d4-4322-a6be-2c75a7e2ddb3&created=1651859776425&expire=1651862072560',
'session-prd-weg': '.eJwtjN1OgzAARt-l13MpP0PhTmGQIhRnkDFvyFq6rVAKocAE47tLohfn5uQ73zcoLj1TN-BczkKxDSg61jdnyeQAnKEfV6OYUryVxdDWTAIHsDm8kYDyhIfoY0Ea5qG9XaVG9WxeWaguJiLs7tNFVuIdtMS7rsRfkfu3yXVRo6qdsUdhkl7vsfesUOPX5CjGMseC_rdEZoq4d3467iYixUCMbEFVB6nMxPrVnfIDT6q9jtO9idPaSLzM3tbRzkevfRlbL0hr8XtraYHVzGG_cFjxB2kb_pvnkmCKFNiAUbG-4CVwdPPRtJ8ghD-_jldbVA.FVb4RQ.oYYEqAK3f1or2w9YGRc-oFgOS_M',
'AMCV_68B620B35350F1650A490D45%40AdobeOrg': '1176715910%7CMCIDTS%7C19119%7CMCMID%7C75681226203198991844515905486944329952%7CMCAAMLH-1652464693%7C7%7CMCAAMB-1652464693%7C6G1ynYcLPuiQxYZrsz_pkqfLG9yMXBpb2zX5dvJdYQJzPXImdj0y%7CMCOPTOUT-1651867093s%7CNONE%7CMCSYNCSOP%7C411-19126%7CvVersion%7C5.4.0',
'mbox': 'session#9b04648bd2964d4d8e40abc012156282#1651863054|PC#9b04648bd2964d4d8e40abc012156282.34_0#1715104736',
'wfm.tracking.sessionStart': '1651859791176',
'AMCVS_68B620B35350F1650A490D45%40AdobeOrg': '1',
'_gcl_au': '1.1.1738690186.1651859792',
'wfmStoreId': '16',
'_fbp': 'fb.1.1651859793593.1868224237',
'_pin_unauth': 'dWlkPU5XUmxNalF6TWpVdE1HVmlPUzAwWWpjMUxUa3dPRGd0TVRrNU5HRXdPV0UwWVdWag',
'__stripe_mid': '033278eb-931c-4c85-b9e4-3b1dc28e5e338dbb2f',
'__stripe_sid': '5a17d4e1-4742-4a54-a943-1454e7d78134335bf1',
'at_check': 'true',
'ajs_anonymous_id': '0eb03156-b0dd-431d-9bb8-41f14db27343',
'wfm.tracking.s10': '1',
'gpv_pn': 'Black%20Bean%20Enchiladas%20%7C%20Wegmans',
's_ppv': 'Black%2520Bean%2520Enchiladas%2520%257C%2520Wegmans%2C24%2C24%2C956%2C1%2C4',
's_ips': '956',
's_tp': '3983',
's_cc': 'true',
's_sq': '%5B%5BB%5D%5D',
'wfm.tracking.x2p': '1',
'_pin_unauth': 'dWlkPU5XUmxNalF6TWpVdE1HVmlPUzAwWWpjMUxUa3dPRGd0TVRrNU5HRXdPV0UwWVdWag',
's_loginSuccess': 'not%20set',
'ajs_anonymous_id': '3beb60b3-6000-47bb-96ee-185813d03e50',
'_uetsid': 'dca98de0cd6511ec929989366717c229',
'_uetvid': 'dcab5500cd6511ecb94c0542b280ea56',
}
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux armv7l; rv:91.0) Gecko/20100101 Firefox/91.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://shop.wegmans.com/recipes/3883/black-bean-enchiladas',
'User-Context': 'eyJTdG9yZUlkIjoiNyIsIkZ1bGZpbGxtZW50VHlwZSI6Imluc3RvcmUifQ==',
'X-Unata-Mode': 'grocery',
'Alt-Used': 'shop.wegmans.com',
'Connection': 'keep-alive',
# Requests sorts cookies= alphabetically
# 'Cookie': '_dd_s=rum=1&id=fc1a0a3f-68d4-4322-a6be-2c75a7e2ddb3&created=1651859776425&expire=1651862072560; session-prd-weg=.eJwtjN1OgzAARt-l13MpP0PhTmGQIhRnkDFvyFq6rVAKocAE47tLohfn5uQ73zcoLj1TN-BczkKxDSg61jdnyeQAnKEfV6OYUryVxdDWTAIHsDm8kYDyhIfoY0Ea5qG9XaVG9WxeWaguJiLs7tNFVuIdtMS7rsRfkfu3yXVRo6qdsUdhkl7vsfesUOPX5CjGMseC_rdEZoq4d3467iYixUCMbEFVB6nMxPrVnfIDT6q9jtO9idPaSLzM3tbRzkevfRlbL0hr8XtraYHVzGG_cFjxB2kb_pvnkmCKFNiAUbG-4CVwdPPRtJ8ghD-_jldbVA.FVb4RQ.oYYEqAK3f1or2w9YGRc-oFgOS_M; AMCV_68B620B35350F1650A490D45%40AdobeOrg=1176715910%7CMCIDTS%7C19119%7CMCMID%7C75681226203198991844515905486944329952%7CMCAAMLH-1652464693%7C7%7CMCAAMB-1652464693%7C6G1ynYcLPuiQxYZrsz_pkqfLG9yMXBpb2zX5dvJdYQJzPXImdj0y%7CMCOPTOUT-1651867093s%7CNONE%7CMCSYNCSOP%7C411-19126%7CvVersion%7C5.4.0; mbox=session#9b04648bd2964d4d8e40abc012156282#1651863054|PC#9b04648bd2964d4d8e40abc012156282.34_0#1715104736; wfm.tracking.sessionStart=1651859791176; AMCVS_68B620B35350F1650A490D45%40AdobeOrg=1; _gcl_au=1.1.1738690186.1651859792; wfmStoreId=16; _fbp=fb.1.1651859793593.1868224237; _pin_unauth=dWlkPU5XUmxNalF6TWpVdE1HVmlPUzAwWWpjMUxUa3dPRGd0TVRrNU5HRXdPV0UwWVdWag; __stripe_mid=033278eb-931c-4c85-b9e4-3b1dc28e5e338dbb2f; __stripe_sid=5a17d4e1-4742-4a54-a943-1454e7d78134335bf1; at_check=true; ajs_anonymous_id=0eb03156-b0dd-431d-9bb8-41f14db27343; wfm.tracking.s10=1; gpv_pn=Black%20Bean%20Enchiladas%20%7C%20Wegmans; s_ppv=Black%2520Bean%2520Enchiladas%2520%257C%2520Wegmans%2C24%2C24%2C956%2C1%2C4; s_ips=956; s_tp=3983; s_cc=true; s_sq=%5B%5BB%5D%5D; wfm.tracking.x2p=1; _pin_unauth=dWlkPU5XUmxNalF6TWpVdE1HVmlPUzAwWWpjMUxUa3dPRGd0TVRrNU5HRXdPV0UwWVdWag; s_loginSuccess=not%20set; ajs_anonymous_id=3beb60b3-6000-47bb-96ee-185813d03e50; _uetsid=dca98de0cd6511ec929989366717c229; _uetvid=dcab5500cd6511ecb94c0542b280ea56',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
# Requests doesn't support trailers
# 'TE': 'trailers',
}
response = requests.get('https://shop.wegmans.com/api/v2/recipes/3883', cookies=cookies, headers=headers)
recipe = response.json()
if __name__ == "__main__":
print(recipe['name'])
print(recipe['preparation_information'])
print("\ningredients")
for i in recipe["ingredients"]:
print(i)
print("\ndirections")
for n,d in enumerate(recipe["directions"]):
print(n+1,". ",d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment