• 0

How do you programmatically expand a url link to its true location?


Question

How do you programmatically expand a url link to its true location?

Do you know about << spam >> and baidu.com? Baidu.com is a search engine that tries to discourage people from using their web site to make metasearch engines by hiding their links in a way that is a lot like how << spam >> works. << spam >> is a web site where, if you want to present someone with a link to something and that link is long, you can use tinyurl to produce a tiny url for presentation purposes.

Anyway, what I want to do is to find a way to programmatically take the link http://www.baidu.com/link?url=mW91GJqjJ4zBBpC8yDF8xDhiqDSn1JZjFWsHhEoSNd85PkV8Xil7qccoOX3rynaE (the first link in a search for Jessica Alba using baidu.com) and have it return the actual link, http://baike.baidu.com/view/270790.htm . That is just one example. What I want to do is not specific to Jessica but for using Baidu.com as part of my group of search engines in my meta search engine project.

Maybe there is a way of using the WebBrowser class but I did not see a member that was the URL.

Maybe there is a way of using WebRequest and WebResponse.

5 answers to this question

Recommended Posts

  • 0
  On 28/11/2012 at 07:36, Complete said:

Maybe there is a way of using the WebBrowser class but I did not see a member that was the URL.

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.url.aspx

  • 0

I'm presuming this in C#...

Anyway, here you go, it's nice and easy! :)

WebRequest WReq = WebRequest.Create("http://www.baidu.com/link?url=mW91GJqjJ4zBBpC8yDF8xDhiqDSn1JZjFWsHhEoSNd85PkV8Xil7qccoOX3rynaE");
WReq.Method = "HEAD"; // Only download the headers, not the page content
WebResponse WRes = WReq.GetResponse();
string ActualURL = WRes.ResponseUri.ToString();
MessageBox.Show(ActualURL);

post-176093-0-27464600-1354088918.png

Personally, I'm curious to what website "<< spam >>" could be :p

  • Like 2
  • 0

I've never really thought about this before, but I'm intrigued by the idea. Thanks -Alex-, I didn't real it was so simple! After playing with it for a few minutes, I managed to accomplish the same thing using cURL (which isn't really anything novel).


curl -s -I http://www.baidu.com/link?url=mW91GJqjJ4zBBpC8yDF8xDhiqDSn1JZjFWsHhEoSNd85PkV8Xil7qccoOX3rynaE | awk '{if($1 == "Location:") print $2}'
[/CODE]

[b]Edit:[/b] Cool! the same thing works with bit.ly.

[CODE]
curl -s -I bit.ly/TuX5wi | awk '{if($1 == "Location:") print $2}'
[/CODE]

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I want to like ^^ this ^^ twice 😛
    • No, it doesn't, but I'm sure you don't just mean compile when you say compile.
    • Wine is a translation layer, not an emulator. And there are many cases where performance is worse or BETTER under Proton, it really depends on the game in question.
    • ImgDrive 2.2.3 by Razvan Serea ImgDrive is a CD/DVD/BD emulator - a tool that allows you to mount optical disc images by simply clicking on them in Windows Explorer. If you have downloaded an ISO image and want to use it without burning it to a blank disc, ImgDrive is the easiest way to do it. ImgDrive features: One-click mounting of iso, cue, nrg, mds/mdf, ccd, isz images Runs on 32-bit and 64-bit Windows versions Mount ape, flac, m4a, wav, wavpack, tta file as AUDIO CD (16-bit/44.1kHz) Mount a folder as DVD/BD Mount images in command line Does not require rebooting after installation Support up to 7 virtual drives at the same time Support multi session disc image (ccd/mds/nrg) A special portable version is available Translated to more than 10 languages ImgDrive is freeware, you may use it at no cost Support File Type: .ccd - CloneCD image files .cue - Cue sheets files of ape/flac/m4a/tta/wav/wv/bin .iso - Standard ISO image files .isz - Compressed ISO image files .nrg - Nero image files .mds - Media descriptor image files ImgDrive 2.2.3 changelog: Some minor changes and improvements Download: ImgDrive 2.2.3 | 701 KB (Freeware, paid upgrade available) Download: ImgDrive Portable 547 KB View: ImgDrive Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
    • First Post
      LsDmT earned a badge
      First Post
    • One Month Later
      evershinefacilityservice earned a badge
      One Month Later
    • Week One Done
      evershinefacilityservice earned a badge
      Week One Done
    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      568
    2. 2
      ATLien_0
      255
    3. 3
      +Edouard
      162
    4. 4
      +FloatingFatMan
      156
    5. 5
      Michael Scrip
      110
  • Tell a friend

    Love Neowin? Tell a friend!