• 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
  • 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

    • Google reshuffles its AI coding team as it struggles to catch Anthropic by Karthik Mudaliar Google is already reorganizing the AI coding “strike team” it created roughly two months ago, as it attempts to find ways to close the gap with Anthropic in one of generative AI’s most commercially important areas. According to The Information, Google DeepMind is expanding the team’s focus to include “midtraining,” rather than concentrating only on coding tools and agents. Midtraining takes place after a model’s broad initial training but before the final stages that prepare it to follow instructions and perform specific tasks. In simple terms, it gives developers another opportunity to expose a model to carefully selected data before it is polished for release. That could help Google improve Gemini’s underlying coding abilities instead of relying only on better prompts, interfaces, or post-training. Previous research has found that midtraining can be particularly effective for code and mathematics, where models must move from general language knowledge to more structured tasks. Google reportedly created the original strike team in April. It was led by Google DeepMind research engineer Sebastian Borgeaud, who previously worked on model pretraining, and focused on complex, long-running programming jobs. Google co-founder Sergey Brin and Google DeepMind chief technology officer Koray Kavukcuoglu were also reportedly involved in the effort. DeepMind researchers were said to believe that Anthropic’s coding tools were outperforming Google’s Gemini models, prompting the company to give the project more attention. Anthropic has made coding a central part of its AI strategy through Claude Code and its Claude model family. The company has continued improving that area, with Claude Opus 4.8 offering upgrades for coding and other agentic tasks, along with the now-unavailable Mythos and Fable models. The reshuffle also comes at a time when Google faces increased competition for AI researchers. Gemini co-lead Noam Shazeer recently announced that he was leaving Google for OpenAI, while two other researchers who contributed to Gemini and DeepMind projects are reportedly preparing to join Anthropic. It remains unclear whether the reorganized team will produce a new public Gemini model or developer product. No release date, team size, or specific performance target has been disclosed. Source: The Information
    • Just remember - Microsoft is a trillion dollar company. They didn't have to raise the price this high. They chose to.
  • Recent Achievements

    • First Post
      kinowa earned a badge
      First Post
    • Rookie
      krychek57 went up a rank
      Rookie
    • Grand Master
      Jaybonaut went up a rank
      Grand Master
    • One Year In
      Philsl earned a badge
      One Year In
    • Dedicated
      Scoobystu earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      413
    2. 2
      +Edouard
      168
    3. 3
      PsYcHoKiLLa
      132
    4. 4
      Xenon
      73
    5. 5
      Michael Scrip
      73
  • Tell a friend

    Love Neowin? Tell a friend!