Jump to content

6 posts in this topic

Posted

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 [url="http://www.baidu.com/link?url=mW91GJqjJ4zBBpC8yDF8xDhiqDSn1JZjFWsHhEoSNd85PkV8Xil7qccoOX3rynaE"]http://www.baidu.com/link?url=mW91GJqjJ4zBBpC8yDF8xDhiqDSn1JZjFWsHhEoSNd85PkV8Xil7qccoOX3rynaE[/url] (the first link in a search for Jessica Alba using baidu.com) and have it return the actual link, [url="http://baike.baidu.com/view/270790.htm"]http://baike.baidu.com/view/270790.htm[/url] . 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.

Share this post


Link to post
Share on other sites

Posted

[quote name='Complete' timestamp='1354088209' post='595354146']
Maybe there is a way of using the WebBrowser class but I did not see a member that was the URL.
[/quote]

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

Share this post


Link to post
Share on other sites

Posted

I'm presuming this in C#...

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

[code]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);[/code]

[attachment=322370:C# Response URI.png]

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

Share this post


Link to post
Share on other sites

Posted

Removed

Share this post


Link to post
Share on other sites

Posted

[quote name='the evn show' timestamp='1354117744' post='595354868']
Probably one of the url shortening services like tiny URL dot com.
[/quote]

a website so simple it was genius

Share this post


Link to post
Share on other sites

Posted

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).

[CODE]
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.