Question

Please help, clarify this issue, I have seen it on many sites now, you type the url, it brings back the title and description and an image as well (facebook for example), how do they do that? tried by ajax on localhost im getting same-origin policy headache.

If not ajax, can u use web streams on server side (php or .net)?

I've looked through stackoverflow and cant find answers. Thank you.

Was it helpful?

Solution 2

To read from another web client-side Ajax does not work, to do that in C# we use

System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.UTF8.GetString(response);

Reading content means parsing the text and looking for certain tags using Regular Expressions, I found no library that'd do the horrendous activity so I had to do it myself

for title

Match TitleMatch = Regex.Match(strIn, "<title>([^<]*)</title>", RegexOptions.IgnoreCase | RegexOptions.Multiline);

for description

Match DescriptionMatch = Regex.Match(strIn, "<meta name=\"description\" content=\"([^<]*)\">", RegexOptions.IgnoreCase | RegexOptions.Multiline);

OTHER TIPS

There is an answer here on how to do it in PHP. If you are wanting to use Ajax, you can use JSONP with PHP. The instructions for exactly how to do this are here

Try to consider this:

 file_get_contents('http://somesite.com.au'); 
 get_meta_tags('http://somesite.com.au');

more info Get information from a web page (title, pictures, heads, etc...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top