admin管理员组文章数量:1123690
I'm trying to crawl data from a website. I can run below script using curl and get response data.
curl ';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: ' \
-H 'priority: u=1, i' \
-H 'referer: /' \
-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'
But it fails when I converted above code to Python:
import requests
url = ';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': '',
'priority': 'u=1, i',
'referer': '/',
'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)
The response is:
403
{"is_customized":false,"is_login":false,"action_type":2,"error":90309999,"tracking_id":"962b030189e-f88d-4fd3-94a7-5e7d2a6550b1"}
I try to use Python, Node.js or Java. But it still failed. It only succeeds when run from bash.
I'm trying to crawl data from a website. I can run below script using curl and get response data.
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'
But it fails when I converted above code to 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)
The response is:
403
{"is_customized":false,"is_login":false,"action_type":2,"error":90309999,"tracking_id":"962b030189e-f88d-4fd3-94a7-5e7d2a6550b1"}
I try to use Python, Node.js or Java. But it still failed. It only succeeds when run from bash.
Share Improve this question edited yesterday Friedrich 4,56111 gold badges45 silver badges42 bronze badges asked yesterday Linh TruongLinh Truong 1 New contributor Linh Truong is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2- 1 Try using curlconverter.com – Sash Sinha Commented yesterday
- already try but still failed. – Linh Truong Commented yesterday
2 Answers
Reset to default 0Use those codes instead
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': '`S"4KD.$`L2e]-ciK(9@cjk.:',
'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)
print(response.status_code)
print(response.text)
Plase try this. The params are passed to requests instead concat with the url.
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())
本文标签: Fail to convert curl to python cdoeStack Overflow
版权声明:本文标题:Fail to convert curl to python cdoe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736589507a1945055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论