Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Recently google has introduced a way to do SEO [Search Engine Optimization] of AJAX ed
webpages.for that they have published the whole rules and protocol here

some popular websites like twitter facebook are moving towards this new coming protocols.they are defining their URL rewrite such a way that it will be having 2 part
shaperated by either #[hashbang] or #![shebang].like the search link of twitter is now
looks like this.they will send only the www.twitter.com to the server and server will response with an ajax which will be needed those extra parameter.for google crawler they will replace "#!" with "?_escaped_fragment_="
and will search for www.twitter.com/?_escaped_fragment_=/search/cts [as per the protocol]

I tried to login programetically Facebook and linkedin using winInet using HTTPS connection.It is working.
but the same code is giving only the home page or error page or an incomplete AJAX code response in case of twitter.
[and also for google hashbang google.co.in/#q=java ]
any body have any idea how to handle this kind of shebang-ed links.

here is the code snippet for twitter:

HINTERNET hOpen =InternetOpen ( "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)", 
			INTERNET_OPEN_TYPE_PRECONFIG, 
			NULL, NULL, 0);
HINTERNET hConnect=		 InternetConnect (
															 hOpen,                      // InternetOpen handle
																"www.twitter.com",             // Server  name
													  INTERNET_DEFAULT_HTTPS_PORT,// Default HTTPS port - 443
																"",                         // User name
																"",                         //  User password
																INTERNET_SERVICE_HTTP,      // Service
													  0,                          // Flags
													  0                           // Context
																   );
//LPCSTR lpData("Content-Type: application/x-www-form-urlencoded"),*lpPtr;
LPCSTR lpData(""),*lpPtr;

lpPtr=&lpData;
		 HINTERNET	  hReq = HttpOpenRequest (
                hConnect,                   // InternetConnect handle
      "GET",                      // Method
      "/?_escaped_fragment_=/search/cts",                         // Object name
      HTTP_VERSION,               // Version
      "",                         // Referrer
	"",              //lpPtr,     // Extra headers
      INTERNET_FLAG_SECURE,       // Flags
      0                           // Context
                );
		
CString csFormat="",csData="";
DWORD dwBytes;//lpData
char ch=' ';
if(HttpSendRequest(hReq,NULL,0,NULL,0))
{
while(InternetReadFile(hReq,&ch,1,&dwBytes))
{
if(dwBytes != 1)break;
putchar(ch);
csFormat.Format("%c",ch);
csData=csData+csFormat;
}
}
			 AfxMessageBox(csData);
//csData is the web content






the incomplete AJAX code returned by twitter is:
t.push(s[r].replace(/\/$/,""))}}return t.join("/")}function j(s,r,i){var q=r.split("/"),t=s;while(q.length>1){t=t[q.shift()]={}}t[q[0]]=i}function f(){}f.prototype.then=function(i){var r=this,q;if(!this.started){this.started=true;if(this.id&&(q=b(this.id))){A(q,function(){r.start()})}else{this.start()}}if(this.completed){i.apply(p,this.results)}else{this.callbacks=this.callbacks||[];this.callbacks.push(i)}return this};f.prototype.start=function(){};f.prototype.complete=function(){if(!this.completed){this.results=M(arguments);this.completed=true;if(this.callbacks){for(var r=0,q;q=this.callbacks[r];r++){q.apply(p,this.results)}}}};function c(q,i){this.id=this.path=q;this.force=!!i}c.loaded=[];c.prototype=new f;c.prototype.start=function(){var i=this,q;if(q=P[this.id]){q.then(function(){i.loaded()})}else{if(!this.force&&Q(c.loaded,this.id)>-1){this.loaded()}else{this.load()}}return this};c.prototype.load=function(){var q=this;P[this.id]=q;var i=n.cloneNode(false);this.scriptId=i.id="LR"+ ++I;i.type="text/javascript";i.async=true;i.onerror=function(){throw new Error(q.path+" not loaded")};i.onreadystatechange=i.onload=function(r){r=p.event||r;if(r.type=="load"||Q(["loaded","complete"],this.readyState)>-1){this.onreadystatechange=null;q.loaded()}};i.src=this.path;U=this;K[0].parentNode.insertBefore(i,K[0]);U=null;G[i.id]=this};c.prototype.loaded=function(){this.complete()};c.prototype.complete=function(){if(Q(c.loaded,this.id)==-1){c.loaded.push(this.id)}delete P[this.id];f.prototype.complete.apply(this,arguments)};function a(q,i){this.id=q;this.body=i;if(typeof i=="undefined"){this.path=this.resolvePath(q)}}a.exports={};a.prototype=new c;a.prototype.resolvePath=function(i){return l(A.path,i+".js")};a.prototype.start=function(){var i,q,r=this,s;if(this.body){this.execute()}else{if(i=a.exports[this.id]){this.exp(i)}else{if(q=V[this.id]){q.then(function(t){r.exp(t)})}else{V[this.id]=this;this.load()}}}};a.prototype.loaded=function(){var q,i,r=this;if(!Z){q=C;C=null;q.id=q.id||this.id;q.then(function(s){r.exp(s)})}else{if(i=a.exports[this.id]){this.exp(i)}else{if(q=V[this.id]){q.then(function(s){r.exp(s)})}}}};a.prototype.complete=function(){delete V[this.id];c.prototype.complete.apply(this,arguments)};a.prototype.execute=function(){var i=this;if(typeof this.body=="object"){this.exp(this.body)}else{if(
Posted
Updated 17-Jun-11 22:26pm
v4

Here is my Asynchronous WinInet code which needs to call by Command line arg.


#include<windows.h>
#include<wininet.h>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
HANDLE hConnectedEvent, hRequestOpenedEvent, hRequestCompleteEvent;
HINTERNET hInstance, hConnect, hRequest;
char *lpszUrl, *lpszServer;
BOOL bAllDone = FALSE;
BOOL bVerbose = FALSE;
void __stdcall Callback(HINTERNET hInternet,
              DWORD dwContext,
              DWORD dwInternetStatus,
              LPVOID lpStatusInfo,
              DWORD dwStatusInfoLen);
void main(int argc, char *argv[])
{
    if (argc != 3)
    {
        if ((argc == 4) && (argv[3][0] == 'v'))
            bVerbose = TRUE;
        else
        {
            cout << "Usage: asynchttp <server> <url> [v]" << endl;
            cout << "   <server> is the hostname of the http server" << endl;
            cout << "   <url> is the url of the object you are requesting (without the hostname)" << endl;
            cout << "   'v' for verbose output" << endl << endl;
            cout << "   Example: asynchttp www.domain.com /docs/readme.htm v" << endl;
            return;
        }
    }
    lpszServer = argv[1];
    lpszUrl = argv[2];
    hConnectedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    hRequestOpenedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    hRequestCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    hInstance = InternetOpen("asynchttp", 
                             INTERNET_OPEN_TYPE_PRECONFIG,
                             NULL,
                             NULL,
                             INTERNET_FLAG_ASYNC); // ASYNC Flag
    if (hInstance == NULL)
    {
        cout << "InternetOpen failed, error " << GetLastError();
        return;
    }
    // Setup callback function
    if (InternetSetStatusCallback(hInstance,
                                  (INTERNET_STATUS_CALLBACK)&Callback) == INTERNET_INVALID_STATUS_CALLBACK)
    {
        cout << "InternetSetStatusCallback failed, error " << GetLastError();
        return;
    }
    // First call that will actually complete asynchronously even
    // though there is no network traffic
    hConnect = InternetConnect(hInstance, 
                               lpszServer, 
                               INTERNET_DEFAULT_HTTP_PORT,
                               NULL,
                               NULL,
                               INTERNET_SERVICE_HTTP,
                               0,
                               1); // Connection handle's Context
    if (hConnect == NULL)
    {
        if (GetLastError() != ERROR_IO_PENDING)
        {
            cout << "InternetConnect failed, error " << GetLastError();
            return;
        }
        // Wait until we get the connection handle
        WaitForSingleObject(hConnectedEvent, INFINITE);
    }

    // Open the request
    hRequest = HttpOpenRequest(hConnect, 
                               "GET", 
                               lpszUrl,
                               NULL,
                               NULL,
                               NULL,
                               INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE,
                               2);  // Request handle's context 
    if (hRequest == NULL)
    {
        if (GetLastError() != ERROR_IO_PENDING)
        {
            cout << "HttpOpenRequest failed, error " << GetLastError();
            return;
        }
        // Wait until we get the request handle
        WaitForSingleObject(hRequestOpenedEvent, INFINITE);
    }
    if (!HttpSendRequest(hRequest, 
                         NULL, 
                         0, 
                         NULL,
                         0))
    {
        if (GetLastError() != ERROR_IO_PENDING)
        {
            cout << "HttpSendRequest failed, error " << GetLastError();
            return;
        }
    }
    
    if (bVerbose)
    {
        cout << "HttpSendRequest called successfully" << endl;
        cout.flush();
    }
    WaitForSingleObject(hRequestCompleteEvent, INFINITE);
    cout << "------------------- Read the response -------------------" << endl;
    char lpReadBuff[256];
	ofstream m_outfile;	
	m_outfile.open ("c:\\test.html", ios::out | ios::app | ios::binary);
    do
    {
        INTERNET_BUFFERS InetBuff;
        FillMemory(&InetBuff, sizeof(InetBuff), 0);
        InetBuff.dwStructSize = sizeof(InetBuff);
        InetBuff.lpvBuffer = lpReadBuff;
        InetBuff.dwBufferLength = sizeof(lpReadBuff) - 1;
        
        if (bVerbose)
        {
            cout << "Calling InternetReadFileEx" << endl;
            cout.flush();
        }
        if (!InternetReadFileEx(hRequest,
                              &InetBuff,
                              0, 2))
        {
            if (GetLastError() == ERROR_IO_PENDING)
            {
                if (bVerbose)
                {
                    cout << "Waiting for InternetReadFileEx to complete" << endl;
                    cout.flush();
                }
                WaitForSingleObject(hRequestCompleteEvent, INFINITE);
            }
            else
            {
                cout << "InternetReadFileEx failed, error " << GetLastError();
                cout.flush();
                return;
            }
        }
        lpReadBuff[InetBuff.dwBufferLength] = 0;
        cout << lpReadBuff;
        m_outfile<<lpReadBuff;
	
	
        cout.flush();
        if (InetBuff.dwBufferLength == 0) 
            bAllDone = TRUE;
    } while (bAllDone == FALSE);
		m_outfile.close();	
    cout << endl << endl << "------------------- Request Complete ----------------" << endl;
int x;
cin>>x;
}
void __stdcall Callback(HINTERNET hInternet,
              DWORD dwContext,
              DWORD dwInternetStatus,
              LPVOID lpStatusInfo,
              DWORD dwStatusInfoLen)
{
    if (bVerbose)
    {
        cout << "Callback dwInternetStatus: " << dwInternetStatus << " Context: " << dwContext << endl;
		if(dwInternetStatus==302)
		{
		int x=0;
		}
        cout.flush();
    }
    switch(dwContext)
    {
    case 1: // Connection handle
        if (dwInternetStatus == INTERNET_STATUS_HANDLE_CREATED)
        {
            INTERNET_ASYNC_RESULT *pRes = (INTERNET_ASYNC_RESULT *)lpStatusInfo;
            hConnect = (HINTERNET)pRes->dwResult;
            if (bVerbose)
            {
                cout << "Connect handle created" << endl;
                cout.flush();
            }
            SetEvent(hConnectedEvent);
        }
        break;
    case 2: // Request handle
        switch(dwInternetStatus)
        {
        case INTERNET_STATUS_HANDLE_CREATED:
            {
                INTERNET_ASYNC_RESULT *pRes = (INTERNET_ASYNC_RESULT *)lpStatusInfo;
                hRequest = (HINTERNET)pRes->dwResult;
                if (bVerbose)
                {
                    cout << "Request handle created" << endl;
                    cout.flush();
                }
                SetEvent(hRequestOpenedEvent);
            }
            break;
        case INTERNET_STATUS_REQUEST_SENT:
            {
                DWORD *lpBytesSent = (DWORD*)lpStatusInfo;
                if (bVerbose)
                {
                    cout << "Bytes Sent: " << *lpBytesSent << endl;
                    cout.flush();
                }
            }
            break;
        case INTERNET_STATUS_REQUEST_COMPLETE:
            {
                INTERNET_ASYNC_RESULT *pAsyncRes = (INTERNET_ASYNC_RESULT *)lpStatusInfo;
                if (bVerbose)
                {
                    cout << "Function call finished" << endl;
                    cout << "dwResult: " << pAsyncRes->dwResult << endl;
                    cout << "dwError:  " << pAsyncRes->dwError << endl;
                    cout.flush();
                }
                SetEvent(hRequestCompleteEvent);
            }
            break;
        case INTERNET_STATUS_RECEIVING_RESPONSE:
            if (bVerbose)
            {
                cout << "Receiving Response" << endl;
                cout.flush();
            }
            break;
        case INTERNET_STATUS_RESPONSE_RECEIVED:
            {
                DWORD *dwBytesReceived = (DWORD*)lpStatusInfo;
                if (*dwBytesReceived == 0)
                    bAllDone = TRUE;
                if (bVerbose)
                {
                    cout << "Received " << *dwBytesReceived << endl;
                    cout.flush();
                }
            }
        }
    }
}
 
Share this answer
 
Ahhh, now I'm with the program (I hope)

Hadn't realized that the content you were after was a result of ajax calls. Now that complicates things considerably I fear. Presumably in order to do those ajax calls, the browser gets the html file as we do, then it parses and begins executing the javascript. Some of which retrieves the search results before inserting it into the (already downloaded) page DOM.


I've done something that seems similar in the past, though the approach I took was to take command of a web-browser and tell it what to do. Then after I'd requested the appropriate page, I could set a delay before getting the page's contents.
It's been ages since I did that. In my case it was to request a dynamically generated list of records. Upon beginning the search, you would be directed to a new page that would complete loading once the results of the search had been compiled into xls and html results and were available for loading. So, I probably just waited until the page had finished loading before reading it - though there were definitely other times that I did a simple, dumb delay before checking contents/proceeding.

Only problem probably is that the code was all dropped into XLS or DOC documents and was all in vba. Of course you can achieve the same functionality in C++, but me and COM and C++ aren't the best buddies yet.

I guess you're more likely not interested than so, however the COM object I used was "InternetExplorer.Application" :)
 
Share this answer
 
Comments
shankha2010 20-Jun-11 5:40am    
:) thanks again for such unbelievably fast response :)

Yaah! that browser handle gives proper response but too slow being a heavy weight process. :(

so what do you think is the difference between an "InternetExplorer.Application" and WinInet is this point of view?
is it
1>WinInet doesn't have any inbuilt Javascript[or AJAX] renderer engine
so it can't load any ajax content?

Is it possible if we come to know after rendering by the browser what is
the next request send to the server[how it looks like]by that AJAX[using "firebug" or "tamper data" or "network monitor" etc.] and programmaticallly
forming the same type of request and sending it?

is it possible?

One more thing ,
I tried with asynchronous WinInet Connection which sometimes gives better result.It allows me to pass the reference of a callback function.where I can monitor the response status.But still I found it is not able to download
AJAX ed content.
So why it is called Asynchronous?
The code is pasted below.[got it some where from codeproject.com]
enhzflep 20-Jun-11 6:16am    
No worries, I enjoy something juicy to chew on!

Yes, I think you've outlined the difference pretty well. InternetExplorer contains calls to WinInet functions (presumably) and couples these with a javascript engine.


Haven't tried it, but yes - that does sound like a good idea to watch network traffic to see what exactly is sent to in order to get the users' details.

I believe it's call Asynchronus because your callback function gets called whenever there's action required, as opposed to the other type - where you enter a continuous loop until receiving a signal that the request is complete. While you can put other tasks into the loop that retrives the received info, it's probably a much better approach to send an asynch request and then go about doing whatever (else) you'd like to do while waiting for the request to finish - the utility code to deal with the incoming stream can then be left away from your program code - you create it once and forget about it. Any changes to desired functionality to occur during the transfer can be programmed in a more appropriate place. - At least that's the way it seems to me. :)
shankha2010 20-Jun-11 9:29am    
Thanks a lot clearly describe all the 3 question :)

ok.. I shall try to track that Ajax response and let you know if found any progress.
I've only just picked up this question, and have now visited Twitter.com exactly once with my browser.

I tried your code and found that I received the entire html, not just the small exerpt that you show above. I then tried to save the response to a file (C:\002\twatter.html) and open that with Chrome to see what it looked like. The only problem was that every time I tried to open the blessed thing, the address bar of my browser would then show
"file:///C:/#!/search/cts/grid?q=cts" and the browser window would show a file listing of the root of my C: drive. Hmmm, hmmm, hmmm.

So I took a closer look inside the response html, and whaddya know - line #9 contained this little gem:
MIDL
window.location.replace('/#!/search/cts/grid?q=cts');


So I tried to enter this url manually, swapping file:///C:/ with twitter.com - to form the url: http://twitter.com/#!/search/cts/grid?q=cts[^]


Sooooo, I guess you can submit the request as normal before buffering the response and searching for the line that begins with "window.location.replace". You could then extract the text contained within the quotes, append that onto the end of the string "www.twitter.com". Once done, you could submit a request for this newly formed url, which in this example given will return a page that (at the time of writing) contains 3 images - some bike riders, an album cover and some people singing.



For reference, here is the returned html from the first request, and the code I used to nab it:

Hope this is the key you require.
Cheers!

XML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

  <script type="text/javascript">
//<![CDATA[
window.location.replace('/#!/search/cts/grid?q=cts');
//]]>
</script>
  <script type="text/javascript">
//<![CDATA[
(function(g){var c=g.location.href.split("#!");if(c[1]){g.location.replace(g.HBR = (c[0].replace(/\/*$/, "") + "/" + c[1].replace(/^\/*/, "")));}else return true})(window);
//]]>
</script>
  <script type="text/javascript">
//<![CDATA[
if(!window.HBR){var matches,url,path,domain;url=document.location.toString();try{domain=url.match(/https?:\/\/[^\/]+/);if(matches=url.match(/(.+?)#(.+)/)){url=matches[1];path=matches[2];if(path){var arr=path.split(/\?/);path=arr[0];var params=arr[1];path=path.replace(/^\//,"");var redirect_url=[domain,path].join("/");if(params){redirect_url=[redirect_url,params].join("?")}document.location=redirect_url}}}catch(err){};}
//]]>
</script>
  <script type="text/javascript">
//<![CDATA[
var page={};var onCondition=function(D,C,A,B){D=D;A=A?Math.min(A,5):5;B=B||100;if(D()){C()}else{if(A>1){setTimeout(function(){onCondition(D,C,A-1,B)},B)}}};
//]]>
</script>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="en-us" http-equiv="Content-Language" />
<meta content="Twitter is without a doubt the best way to share and discover what is happening right now." name="description" />
<meta content="no" http-equiv="imagetoolbar" />
<meta content="width = 780" name="viewport" />
<meta content="4FTTxY4uvo0RZTMQqIyhh18HsepyJOctQ+XTOu1zsfE=" name="verify-v1" />
<meta content="1" name="page" />
<meta content="NOODP" name="robots" />
<meta content="n" name="session-loggedin" />
  <title id="page_title">Twitter / Search</title>
  <link href="https://si0.twimg.com/a/1308256633/images/twitter_57.png" rel="apple-touch-icon" />
<link href="/oexchange.xrd" rel="http://oexchange.org/spec/0.8/rel/related-target" type="application/xrd+xml" />
<link href="https://si0.twimg.com/a/1308256633/images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
  <link href="https://si0.twimg.com/a/1308256633/stylesheets/fronts.css?1308259136" media="screen" rel="stylesheet" type="text/css" />

  </head>

<body class="timeline ie ie8 front" id="search">
  <script type="text/javascript">
//<![CDATA[
document.domain = 'twitter.com';function fn(){document.write = "";window.top.location = window.self.location;setTimeout(function(){document.body.innerHTML = '';},0);window.self.onload = function(evt){document.body.innerHTML = '';};}if(window.top !== window.self){try{if(window.top.location.host){}else{fn();}}catch(e){fn();}}
//]]>
</script>

  <div id="header">
  <div class="background">
    <div class="inner">
      <div id="logo-search">
        <a href="/" id="logo"><img alt="Twitter" height="55" src="https://si0.twimg.com/a/1308256633/images/fronts/logo_withbird_home.png" width="224" /></a>
        <form action="/search" id="home_search" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="23f64499bc7bd8f3b4dc82d221063563caabe68d" /></div>
          <p>
            <input accesskey="/" class="round-left" id="searchform_q" name="q" size="30" tabindex="8" type="text" value="cts" /><input class="submit round-right" id="searchform_submit" name="commit" tabindex="9" type="submit" value="Search" />
          </p>
        </form>
        <p id="tag">
          The best way to discover what&rsquo;s new in your world.
        </p>
      </div>
      <div id="topnav">
        <div id="signin-c">
          <div id="signin_controls">
  <span id="have_an_account">
    Have an account?<a href="/login" class="signin" tabindex="3"><span>Sign in</span></a></span>
  <div id="signin_menu" class="common-form standard-form offscreen">

    <form method="post" id="signin" action="https://twitter.com/sessions">

  <input id="authenticity_token" name="authenticity_token" type="hidden" value="23f64499bc7bd8f3b4dc82d221063563caabe68d" />  <input id="return_to_ssl" name="return_to_ssl" type="hidden" value="true" />
  <input id="redirect_after_login" name="redirect_after_login" type="hidden" value="/search/cts/grid" />  <p class="textbox">
    <label for="username">Username or email</label>
    <input type="text" id="username" name="session[username_or_email]" value="" title="username" tabindex="4"/>
  </p>

  <p class="textbox">
    <label for="password">Password</label>
    <input type="password" id="password" name="session[password]" value="" title="password" tabindex="5"/>
  </p>

  <p class="remember">
    <input type="submit" id="signin_submit" value="Sign in" tabindex="7"/>
    <input type="checkbox" id="remember" name="remember_me" value="1" tabindex="6"/>
    <label for="remember">Remember me</label>
  </p>

  <p class="forgot">
    <a href="/account/resend_password" id="resend_password_link">Forgot password?</a>
  </p>

  <p class="forgot-username">
    <a href="/account/resend_password" id="forgot_username_link" title="If you remember your password, try logging in with your email">Forgot username?</a>
  </p>
    <p class="complete">
      <a href="/account/complete" id="account_complete_link">Already using Twitter on your phone?</a>
    </p>
  <input type="hidden" name="q" id="signin_q" value="cts"/>
  </form>
</div>

</div>


        </div>
      </div>
      <div class="overlay">
  <div class="newuser">
    <h2>New to Twitter?</h2>
    <p>Easy, free, and instant updates. Get access to the information that interests you most.</p>
    <p id="signup-btn"><a href="/signup" id="signup_submit" tabindex="10"><span>Sign Up &rsaquo;</span></a></p>

      <h2>Discover Twitter</h2>
      <p><a href="http://discover.twitter.com/?autoplay=true">Find out how</a> some of your favorite people use Twitter.</p>
      <p><a href="http://discover.twitter.com/?autoplay=true" id="video-thumb"><img alt="Discover-video" height="140" src="https://si0.twimg.com/a/1308256633/images/fronts/discover-video.png" width="200" /></a></p>

  </div>
</div>

    </div>
  </div>



<div id="trends">

  <div class="inner">
      <ul class="trendscontent">


              <li class="trend-label">Trending topics</li>

          <li>
            <a href="http://twitter.com/search?q=%22Brittany%20Murphy%22" class="search_link" name="&quot;Brittany Murphy&quot;" rel="nofollow">Brittany Murphy</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Penn%20&%20Teller%22" class="search_link" name="&quot;Penn &amp; Teller&quot;" rel="nofollow">Penn &amp; Teller</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Epic%20Movie%22" class="search_link" name="&quot;Epic Movie&quot;" rel="nofollow">Epic Movie</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=Ighalo" class="search_link" name="Ighalo" rel="nofollow">Ighalo</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Glen%20Coco%22" class="search_link" name="&quot;Glen Coco&quot;" rel="nofollow">Glen Coco</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Her%20Room%22" class="search_link" name="&quot;Her Room&quot;" rel="nofollow">Her Room</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Mauro%20Diaz%22" class="search_link" name="&quot;Mauro Diaz&quot;" rel="nofollow">Mauro Diaz</a>

          </li>


              <li class="trend-label">Trending topics</li>

          <li>
            <a href="http://twitter.com/search?q=%22Teyana%20Taylor%22" class="search_link" name="&quot;Teyana Taylor&quot;" rel="nofollow">Teyana Taylor</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Lar%20Doce%20Lar%22" class="search_link" name="&quot;Lar Doce Lar&quot;" rel="nofollow">Lar Doce Lar</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Jos%C3%A9%20Saramago%22" class="search_link" name="&quot;José Saramago&quot;" rel="nofollow">José Saramago</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Brigitte%20Kaandorp%22" class="search_link" name="&quot;Brigitte Kaandorp&quot;" rel="nofollow">Brigitte Kaandorp</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=Elche-Granada" class="search_link" name="Elche-Granada" rel="nofollow">Elche-Granada</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=Wetten" class="search_link" name="Wetten" rel="nofollow">Wetten</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Undisclosed%20Desires%22" class="search_link" name="&quot;Undisclosed Desires&quot;" rel="nofollow">Undisclosed Desires</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22SCORPIOS%20RULE%22" class="search_link" name="&quot;SCORPIOS RULE&quot;" rel="nofollow">SCORPIOS RULE</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Bald%20Gaga%22" class="search_link" name="&quot;Bald Gaga&quot;" rel="nofollow">Bald Gaga</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Maria%20Desamparada%22" class="search_link" name="&quot;Maria Desamparada&quot;" rel="nofollow">Maria Desamparada</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22United%20Airlines%22" class="search_link" name="&quot;United Airlines&quot;" rel="nofollow">United Airlines</a>

          </li>


          <li>
            <a href="http://twitter.com/search?q=%22Ryan%20Reynolds%22" class="search_link" name="&quot;Ryan Reynolds&quot;" rel="nofollow">Ryan Reynolds</a>

          </li>

      </ul>
  </div>
  <span class="fade fade-left">&nbsp;</span><span class="fade fade-right">&nbsp;</span>

</div>



</div>

  <ul id="accessibility" class="offscreen">
  <li><a href="#content" accesskey="0">Skip past navigation</a></li>
  <li>On a mobile phone? Check out <a href="http://m.twitter.com/">m.twitter.com</a>!</li>
  <li><a href="#footer" accesskey="2">Skip to navigation</a></li>
    <li><a href="#signin">Skip to sign in form</a></li>
</ul>


  <div class="content-wrapper">
    <div id="content" class="homepage">


<div class="section clearfix">
  <div class="aside">


          <div class="trenddesc" style="display:none">
    <span class="trending">Trending Now</span>

    <div id="trend"></div>

    <div id="trend_description"><p></p></div>

    <div id="what_the_trend">Source: <span>What the Trend?</span></div>
  </div>
  <div class="current-trends" style="display:none">
    <h3>Top Trending Topics</h3>
    <ul>

        <li><a href="http://twitter.com/search?q=%23howtopleaseahoodrat" class="search_link" name="#howtopleaseahoodrat" rel="nofollow">#howtopleaseahoodrat</a></li>

        <li><a href="http://twitter.com/search?q=%23nextfriday" class="search_link" name="#nextfriday" rel="nofollow">#nextfriday</a></li>

        <li><a href="http://twitter.com/search?q=%23trespalabrasespanolas" class="search_link" name="#trespalabrasespanolas" rel="nofollow">#trespalabrasespanolas</a></li>

        <li><a href="http://twitter.com/search?q=%22Brittany%20Murphy%22" class="search_link" name="&quot;Brittany Murphy&quot;" rel="nofollow">Brittany Murphy</a></li>

        <li><a href="http://twitter.com/search?q=%22Penn%20&%20Teller%22" class="search_link" name="&quot;Penn &amp; Teller&quot;" rel="nofollow">Penn &amp; Teller</a></li>

        <li><a href="http://twitter.com/search?q=%22Epic%20Movie%22" class="search_link" name="&quot;Epic Movie&quot;" rel="nofollow">Epic Movie</a></li>

        <li><a href="http://twitter.com/search?q=Ighalo" class="search_link" name="Ighalo" rel="nofollow">Ighalo</a></li>

        <li><a href="http://twitter.com/search?q=%22Glen%20Coco%22" class="search_link" name="&quot;Glen Coco&quot;" rel="nofollow">Glen Coco</a></li>

        <li><a href="http://twitter.com/search?q=%22Her%20Room%22" class="search_link" name="&quot;Her Room&quot;" rel="nofollow">Her Room</a></li>

        <li><a href="http://twitter.com/search?q=%22Mauro%20Diaz%22" class="search_link" name="&quot;Mauro Diaz&quot;" rel="nofollow">Mauro Diaz</a></li>

    </ul>
  </div>



    <div class="search-tip" style="display:none">
      <h3>Search tip</h3>
      <div>Use <em>:(</em> to find tweets with a negative or sad attitude. Example: <a href="/search?q=flight+%3A%28">flight :(</a> will find tweets containing "flight" and with a negative attitude.</div>
    </div>

      <div style="height:285px"></div>

  </div>
  <div class="article">
    <div id="tweets" data="{timeout:8000}">
      <h2>Top Tweets <a id="view_all_top_tweets" href="toptweets/favorites" tabindex="11">View all</a></h2>

        <script src="https://si0.twimg.com/a/1308256633/javascripts/widgets/widget.js?1308259133" type="text/javascript"></script>
<script type="text/javascript">
  //height was 202 to match 5 lines of sources
  new TWTR.Widget({
    version: 2,
    type: 'faves',
    rpp: 40,
    interval: 6000,
    title: 'Noteworthy tweets',
    subject: '',
    width: 'auto',
    height: '270',
    theme: {
      shell: {
        background: '#ffffff',
        color: '#333333'
      },
      tweets: {
        background: '#ffffff',
        color: '#333333',
        links: '#2276bb'
      }
    },
    features: {
      scrollbar: false,
      loop: true,
      live: true,
      hashtags: true,
      timestamp: true,
      avatars: true,
      behavior: 'preloaded'
    }
  }).render().setUser("toptweets").start();
</script>


    </div>
    <div id="results" style="display: none">
      <h2 id="timeline_heading">Realtime results for <span></span></h2>
              <div data="&#123;&quot;search&quot;:&#123;&quot;delay&quot;:20,&quot;decay&quot;:1.25,&quot;max_delay&quot;:180&#125;,&quot;timeline&quot;:&#123;&quot;max_refresh_size&quot;:40,&quot;delay&quot;:30,&quot;decay&quot;:1.5,&quot;max_delay&quot;:300&#125;&#125;" id="new_results_notification"><a accesskey="n" class="minor-notification" id="results_update" style="display:none;"></a></div>

      <div class="no-results"></div>
      <ol id="timeline" class="statuses"></ol>
      <div id="pagination"></div>
    </div>
  </div>
</div>


    </div>
  </div>

  <div class="footer-wrapper">

  <div id="footer" class="round wide">
      <h3 class="offscreen">Footer</h3>


  <form action="/sessions/change_locale" id="lf" method="post" style="display:none;"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="23f64499bc7bd8f3b4dc82d221063563caabe68d" /></div>
  <input type="hidden" name="lang"  id="lang" value="en"/>
</form>
<ul class="language-select"><li>Language:</li><li><a href="#" class="locale">English</a>&nbsp;<a href="#" class="arrow">&#9660;</a></li></ul>
<ol class="language-menu round">
  <li id="pt">Portuguese - Português</li>
  <li id="it">Italian - Italiano</li>
  <li id="es">Spanish - Español</li>
  <li id="tr">Turkish - Türkçe</li>
  <li id="en">English</li>
  <li id="ko">Korean - 한국어</li>
  <li id="fr">French - français</li>
  <li id="ru">Russian - Русский</li>
  <li id="de">German - Deutsch</li>
  <li id="ja">Japanese - 日本語</li>
</ol>

      <ul class="footer-nav">
          <li class="first">&copy; 2011 Twitter</li>
          <li><a href="/about">About Us</a></li>
          <li><a href="/about/contact">Contact</a></li>
          <li><a href="http://blog.twitter.com">Blog</a></li>
          <li><a href="http://status.twitter.com">Status</a></li>
                      <li><a href="/about/resources">Resources</a></li>
                    <li><a href="http://dev.twitter.com/">API</a></li>
                      <li><a href="http://twitter.com/business">Business</a></li>
                    <li><a href="http://support.twitter.com">Help</a></li>
          <li><a href="/help/jobs">Jobs</a></li>
          <li><a href="/tos">Terms</a></li>
          <li><a href="/privacy">Privacy</a></li>
      </ul>
  </div>


  </div>

  <div class="trendtip">
  <div class="trendtip-content">
    <div>Trending right now:</div>
    <a class="trendtip-trend"></a>
    <div class="trendtip-why">
      Why?
      <span class="trendtip-desc"></span>
      <span class="trendtip-source">Source: <span>What the Trend?</span></span>
    </div>
  </div>
  <div class="trendtip-pointer">&nbsp;</div>
</div>



  <div id="notifications"></div>




  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js" type="text/javascript"></script>
<script src="https://si0.twimg.com/a/1308256633/javascripts/fronts-https.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
  page.summizeSearchUrl = 'http://search.twitter.com/search';
  page.query = 'cts';
  page.prettyQuery = '';
  page.locale = 'en';

    page.showSS = true;


//]]>
</script>
<script type="text/javascript">
//<![CDATA[

      $( function () {

  setTimeout(function() { $(".twtr-widget").append($("<div></div>").attr("class", "twtr-fade")); }, 0);

  var tabIndex = $("[tabindex]:last").attr("tabIndex");
  var setTabIndex = function() {
    $(this).attr("tabindex", ++tabIndex);
  }
  $(".footer-nav a").each(setTabIndex);
  $(".language-select a").each(setTabIndex);

   searchSummize(
     'cts',
     $('#home_search'),
     'processHomepageSearch'
   );

(function(g){function b(){var c=g.location.href.split("#!");if(c[1]){g.location.replace(g.HBR = (c[0].replace(/\/*$/, "") + "/" + c[1].replace(/^\/*/, "")));}else return true}var a="onhashchange"in g;if(!a&&g.setAttribute){g.setAttribute("onhashchange","return;");a=typeof g.onhashchange==="function"}if(a)$(g).bind("hashchange",b);else{var d=function(){b()&&setTimeout(d,250)};setTimeout(d,250)}}(window));
  $('#signin_menu').isSigninMenu();

      new FrontPage().init();

      $('#newbar .hashtag').isSearchLink(SEARCH_CALLBACKS.hashtagLink);


      });

//]]>
</script>
      <!-- BEGIN google analytics -->

  <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  </script>

  <script type="text/javascript">

    try {
      var pageTracker = _gat._getTracker("UA-30775-6");
      pageTracker._setDomainName("twitter.com");
            pageTracker._setVar('Not Logged In');
            pageTracker._setVar('lang: en');
            pageTracker._initData();
                } catch(err) { }

  </script>

  <!-- END google analytics -->



</body>
</html>



void doTwatterSearch()
{
    HINTERNET hOpen =InternetOpen ( "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)",
                                    INTERNET_OPEN_TYPE_PRECONFIG,
                                    NULL, NULL, 0);
    HINTERNET hConnect=		 InternetConnect (
                                 hOpen,                      // InternetOpen handle
                                 "www.twitter.com",             // Server  name
                                 INTERNET_DEFAULT_HTTPS_PORT,// Default HTTPS port - 443
                                 "",                         // User name
                                 "",                         //  User password
                                 INTERNET_SERVICE_HTTP,      // Service
                                 0,                          // Flags
                                 0                           // Context
                             );
//LPCSTR lpData("Content-Type: application/x-www-form-urlencoded"),*lpPtr;
    LPCSTR lpData(""),*lpPtr;
    lpPtr=&lpData;
    HINTERNET	  hReq = HttpOpenRequest (
                             hConnect,                   // InternetConnect handle
                             "GET",                      // Method
                             "/?_escaped_fragment_=/search/cts",                         // Object name
                             HTTP_VERSION,               // Version
                             "",                         // Referrer
                             (const CHAR**)"text/*",              //lpPtr,     // Extra headers
                             INTERNET_FLAG_SECURE,       // Flags
                             0                           // Context
                         );
    DWORD dwBytes;//lpData
    FILE *fp;
    char ch=' ';
    if(HttpSendRequest(hReq,NULL,0,NULL,0))
    {
        fp = (FILE*)fopen("C:\\002\\twatter.html", "w+");
        while(InternetReadFile(hReq,&ch,1,&dwBytes))
        {
            if(dwBytes != 1) break;
            //printf("%c",ch);
            fprintf(fp, "%c", ch);
        }
        fclose(fp);
    }
}
 
Share this answer
 
Comments
shankha2010 20-Jun-11 2:19am    
First of all a great thanks for the response.

if you directly search with this link http://www.twitter.com/#!/search/cts
you can find out list of some people from cts.[please past it in address bar manually]
I don't want the search result from the image page as you told above.
I tried the code you mentioned above but it is returning only the home page of twitter in google crome and in IE it is opening C directory content [as you told] .
But I want those person's name[means search result which is loading by AJAX call] in that "twatter.html" file

and last of all thanks for showing those changes in my code.As i am new in WinInet programming really this small tips helps me a lot.


Thanks again and waiting for the reply :)


[one more question: Is there any place to put delay to get the AJAX load completely to get those
content in file?]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900