Dear All, I have a list of URLs in an excel sheet. When clicked on each link, it opens into a browser but the URL in browser is different. For example, a link in excel is “https://management.work.com/9/08FA1065-0BC2-9F1F-9534E6/ebi/pdf/?productID=13403” but when click on it, it opens in browser with URL " (https://management.work.com/9/08FA1065-0BC2-4CF7-9F1F-95345B8D80E6/pdf/IPQ597)". I need to extract a URL after the link is open in browser. To be precise, I need to get the code which appears last in open URL. In above example the code I want is “IPQ597”. I need these codes for all the URLs in my excel sheet. Is there a way I could get in quick time? Power automate desktop can do it but it takes longer time. Thanks a lot in advance.
The reason for this is some kind of page redirect. This can either be done by the server (for example, you might get a status code like 301 if you try visiting the URL; you can see this if you write code that directly accesses the URL instead of working through a web browser), or by the client (because the resulting page contains some Javascript that tells a web browser to load a different URL). In the latter case you will not have a simple answer, because the only way to be sure what the Javascript code does is to actually run it. Automation tools will solve the problem by automating your browser to open the URL, but as you have seen it is slow.
Dear Karl,
Thanks for your feedback. I guess I got a way to get the details which I intend. The code i used is below
url = “https://management.work.com/9/08FA1065-0BC2-9F1F-9534E6/ebi/pdf/?productID=13403”
r = requests.get(url)
print(r.url)
Using this code i got the desired url i:e (https://management.work.com/9/08FA1065-0BC2-4CF7-9F1F-95345B8D80E6/pdf/IPQ597)".
Now i just need to loop this code for each url. Could you please help me with code for looping all these URLs. I think of 2 ways,
1st way : All of my initial url are same except the product ID in the end. In above case its “13403”. So I kept this as Prefix. Then I created a suffix for all the 1k+ product ID. For example - suffix = (“13403” + “13404” + “13405”…so on. Then I ran the code, as you can guess its not working.
2nd way : To loop through all the url from excel one by one. I dont know how to write code for that.
could you please help.
PS: for business security, all my urls mentioned here are incomplete. I hope you understand.