How do I get the final URL from a redirect link? (like requests.get from python)?

44 ビュー (過去 30 日間)
Zikora Agbapu
Zikora Agbapu 2020 年 8 月 7 日
回答済み: Mohammad Sami 2022 年 4 月 7 日
I'm using a SERP API to return Google Shopping links, and sometimes it returns Google aclk redirect links. In Python, the requests.get command and accessing the .url field gives me what I'm looking for. I tried using python within Matlab and it works with a single url, but when I try to use within a for loop it always freezes.
  2 件のコメント
Hank Helmers
Hank Helmers 2022 年 4 月 6 日
What is the Request.get method equivalent in matlab that you got to work?


回答 (1 件)

Mohammad Sami
Mohammad Sami 2022 年 4 月 7 日
You can use the interface to follow the redirects.
request =;
uri ='');
[response,completedrequest,history] = send(request,uri);
finaluri = history(end).URI;
URI with properties: Scheme: "https" UserInfo: [0×0 string] Host: "" Port: [] EncodedAuthority: "" Path: ["" "maps" "place" "Houston,+TX,+USA" "@29.8174782,-95.6814846,10z" "data=!3m1!4b1!4m5!3m4!1s0x8640b8b4488d8501:0xca0d02def365053b!8m2!3d29.7596088!4d-95.3723145"] EncodedPath: "/maps/place/Houston,+TX,+USA/@29.8174782,-95.6814846,10z/data=!3m1!4b1!4m5!3m4!1s0x8640b8b4488d8501:0xca0d02def365053b!8m2!3d29.7596088!4d-95.3723145" Query: [1×1] EncodedQuery: "shorturl=1" Fragment: [0×0 string] Absolute: 1 EncodedURI: ",+TX,+USA/@29.8174782,-95.6814846,10z/data=!3m1!4b1!4m5!3m4!1s0x8640b8b4488d8501:0xca0d02def365053b!8m2!3d29.7596088!4d-95.3723145?shorturl=1"


Help Center および File ExchangePython Package Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by