我正在尝试从网站获取数据。 我可以运行下面的脚本,使用curl成功并获取响应数据
curl 'https://gappapi.deliverynow.vn/api/dish/get_delivery_dishes?id_type=2&request_id=112049' \
-H '1d9d7338: `S"4KD.$`L2e]-ciK(9@cjk.:' \
-H $'291810e4: o^L+Vl^kIoFe5sN.U^eRC0GJr<tg7[\u00212Yef*:]W=3@3L-[]lgfFtr(E(*oG5IX/*Y`/Fi<ZVpO<Z_kQ%ZqdVYl5t<0\\"*]d&p]afP<]i#jH\u0021ugS=Y"@jXQ]O/8NsSVBDnP\\\u0021Gq/n-"_h<oc+bY-[h/&77\'B0Vr?)[VKXIZ1)b=kX8H+96i(^4Q2c[Uuso1Y@uEH96i(^4Q2c[Uuso1Y@uEH' \
-H $'972ad465: $]3ge$\u0021/\u0021UUjUR:b\'+,_1pd?q' \
-H 'accept: application/json, text/plain, */*' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'origin: https://shopeefood.vn' \
-H 'priority: u=1, i' \
-H 'referer: https://shopeefood.vn/' \
-H 'sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: cross-site' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' \
-H 'x-foody-access-token;' \
-H 'x-foody-api-version: 1' \
-H 'x-foody-app-type: 1004' \
-H 'x-foody-client-id;' \
-H 'x-foody-client-language: vi' \
-H 'x-foody-client-type: 1' \
-H 'x-foody-client-version: 3.0.0' \
-H 'x-sap-ri: bd9680675ed346a848ed80363271537322eab82e6ddd0e5f'
但是当我将上面的代码转换为Python脚本时。
失败了。
import requests
url = 'https://gappapi.deliverynow.vn/api/dish/get_delivery_dishes?id_type=2&request_id=112049'
headers = {
'1d9d7338': '`S"4KD.$`L2e]-ciK(9@cjk.:',
'291810e4': r'o^L+Vl^kIoFe5sN.U^eRC0GJr<tg7[\u00212Yef*:]W=3@3L-[]lgfFtr(E(*oG5IX/*Y`/Fi<ZVpO<Z_kQ%ZqdVYl5t<0\\"*]d&p]afP<]i#jH\u0021ugS=Y"@jXQ]O/8NsSVBDnP\\\u0021Gq/n-"_h<oc+bY-[h/&77\'B0Vr?)[VKXIZ1)b=kX8H+96i(^4Q2c[Uuso1Y@uEH96i(^4Q2c[Uuso1Y@uEH',
'972ad465': r'$]3ge$\u0021/\u0021UUjUR:b\'+,_1pd?q',
'accept': 'application/json, text/plain, */*',
'accept-language': 'en-US,en;q=0.9',
'origin': 'https://shopeefood.vn',
'priority': 'u=1, i',
'referer': 'https://shopeefood.vn/',
'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'x-foody-access-token': '',
'x-foody-api-version': '1',
'x-foody-app-type': '1004',
'x-foody-client-id': '',
'x-foody-client-language': 'vi',
'x-foody-client-type': '1',
'x-foody-client-version': '3.0.0',
'x-sap-ri': 'bd9680675ed346a848ed80363271537322eab82e6ddd0e5f'
}
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.text)
回复是:
403
{"is_customized":false,"is_login":false,"action_type":2,"error":90309999,"tracking_id":"962b030189e-f88d-4fd3-94a7-5e7d2a6550b1"}
请帮助我。
我尝试使用 python、nodejs 或 java。但它仍然失败了。 只有从 bash 运行时才会成功。
请尝试这个:
import requests
url = "https://gappapi.deliverynow.vn/api/dish/get_delivery_dishes"
params = {
"id_type": "2",
"request_id": "112049",
}
headers = {
"1d9d7338": "`S\"4KD.$`L2e]-ciK(9@cjk.:",
"291810e4": "o^L+Vl^kIoFe5sN.U^eRC0GJr<tg7[!2Yef*:]W=3@3L-[]lgfFtr(E(*oG5IX/*Y`/Fi<ZVpO<Z_kQ%ZqdVYl5t<0\"*]d&p]afP<]i#jH!ugS=Y\"@jXQ]O/8NsSVBDnP\\!Gq/n-\"_h<oc+bY-[h/&77'B0Vr?)[VKXIZ1)b=kX8H+96i(^4Q2c[Uuso1Y@uEH96i(^4Q2c[Uuso1Y@uEH",
"972ad465": "$]3ge$!/!UUjUR:b'+,_1pd?q",
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
"origin": "https://shopeefood.vn",
"priority": "u=1, i",
"referer": "https://shopeefood.vn/",
"sec-ch-ua": '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Linux"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
"x-foody-access-token": "",
"x-foody-api-version": "1",
"x-foody-app-type": "1004",
"x-foody-client-id": "",
"x-foody-client-language": "vi",
"x-foody-client-type": "1",
"x-foody-client-version": "3.0.0",
"x-sap-ri": "bd9680675ed346a848ed80363271537322eab82e6ddd0e5f",
}
response = requests.get(url, headers=headers, params=params)
print(response.json())