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

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

Did you ever work this out?
What is the Request.get method equivalent in matlab that you got to work?

댓글을 달려면 로그인하십시오.

답변 (1개)

You can use the matlab.net.http interface to follow the redirects.
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI('https://goo.gl/maps/co8U2mMv8zFweDzN8');
[response,completedrequest,history] = send(request,uri);
finaluri = history(end).URI;
disp(finaluri);
URI with properties: Scheme: "https" UserInfo: [0×0 string] Host: "www.google.com" Port: [] EncodedAuthority: "www.google.com" 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 matlab.net.QueryParameter] EncodedQuery: "shorturl=1" Fragment: [0×0 string] Absolute: 1 EncodedURI: "https://www.google.com/maps/place/Houston,+TX,+USA/@29.8174782,-95.6814846,10z/data=!3m1!4b1!4m5!3m4!1s0x8640b8b4488d8501:0xca0d02def365053b!8m2!3d29.7596088!4d-95.3723145?shorturl=1"

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2020년 8월 7일

답변:

2022년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by