Thread: Google and c

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Angel45
    what is stored in the result_box actually is the result translated split by words per line. It is a little hard to find through reading it but you can find it.
    Uh, if by "find it" you mean find it in the source as inspected using your browser's developers' tool, then you should note that the tool may be displaying the source to correspond to the page as it is rendered. When you actually access the page programmatically, on the other hand, that result text would not be present if it is obtained through AJAX. In fact, I observe that the input is displayed in my browser's address bar in the URL fragment rather than the query string. This hints that there is clientside scripting that takes the fragment for processing since the fragment is not transferred server side.
    Last edited by laserlight; 04-03-2012 at 11:47 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    Yeah by find it I mean the browsers developers tool. And the way I have programmed so far to take in a string and format the string so it is then the correct url for the translation. I wonder if there is a way to get the info from the developer tools. I am still looking for a way how to do that.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Angel45
    And the way I have programmed so far to take in a string and format the string so it is then the correct url for the translation.
    What URL might this be?

    Quote Originally Posted by Angel45
    I wonder if there is a way to get the info from the developer tools. I am still looking for a way how to do that.
    Uh, that sounds like you'll be making a Rube Goldberg machine.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    An example is this you type in "Translating is fun" and it scans in the string and then formats the string to make the url Google Translate look at the ending characters being en|no| standing for english to norwegian. and then the words separated by %20. And yes I am making it very complex for something that could be easier, but I want to be able to do this for more than just this case.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Angel45
    An example is this you type in "Translating is fun" and it scans in the string and then formats the string to make the url Google Translate
    Yes, but that is the URL of the service frontend, not the URL to which you can send a request to get a response that can be parsed for the translation.

    Quote Originally Posted by Angel45
    look at the ending characters being en|no| standing for english to norwegian. and then the words separated by %20.
    Refer to my post #16. As I said, you are looking at the fragment identifier, not the query string.

    Quote Originally Posted by Angel45
    And yes I am making it very complex for something that could be easier, but I want to be able to do this for more than just this case.
    Since you are so insistent on trying to parse the source of a page even when it does not contain the data that you want, maybe you should try a different service instead, one that does present the data directly. For example, try parsing for the definition of words through the dictionary.reference.com service.
    Last edited by laserlight; 04-04-2012 at 08:45 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    I am starting to understand what you are saying I think. Can I have the URL front end run and then collect the information from the developers tools after it runs. I am extremly determined to do it this way, or close to this way, sorry if I am being stubborn, just want to learn how to do this from scratch. There was a question I heard from someone earlier today talking about doing this using python, they refuse to share their secrets haha.

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Angel45
    Can I have the URL front end run and then collect the information from the developers tools after it runs.
    It may be possible, but why do it that way?

    Quote Originally Posted by Angel45
    I am extremly determined to do it this way, or close to this way, sorry if I am being stubborn, just want to learn how to do this from scratch.
    What do you mean by "do this from scratch"?

    Basically, when a user visits the Google Translate page and gets a translation, there is client side scripting on the page that sends the text to the server in the request, receives the translation in the response, and renders it on the page. I am just saying that if you don't want to use the official API, then an approach that might work is to write your own client that does the same thing, except that the input/output is from/to your own program.

    If this is not doing it from scratch, then what you are trying to do is not doing it from scratch either.

    Also, if you "want to be able to do this for more than just this case", then going through Google Chrome developer tools is hardly going to facilitate such reuse of skills, whereas doing what I suggested will.

    Quote Originally Posted by Angel45
    There was a question I heard from someone earlier today talking about doing this using python, they refuse to share their secrets haha.
    As in going through Google Chrome developer tools?
    Last edited by laserlight; 04-05-2012 at 02:53 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    If it works via AJAX, you have to figure out the format of the message passed back and forth. You could look at the raw transmission as memcpy suggests, but that may not help very much all by itself. You also need to find the javascript calls involved and see how the data in the message is serialized, where it comes from client side, and how the response is used. This will be tedious as google compacts their scripts and tend to use very uninformative and minimal variable names, etc. I haven't used the Chrome tools, but presuming they do something like Firebug, you should be able to watch the transmissions occurring and possibly trace the js calls. You then need to mimic their output (which you could do in C or python or whatever), keeping in mind that some of the information maybe, eg, a cookie value intended to prevent people from easily spoofing the service this way. It cannot be made impossible, nb., but it can be made more difficult: if a cookie is involved, you will have to figure out how it came to be, a way to get such a token first, and then use it properly in the "ajax" exchange.

    Unfortunately, Angel45, your understanding of how web applications work sounds a little simplistic, meaning you may have to learn a lot just to attempt this. Again, not impossible, but if the official API looks easy enough to use, it may be worth the $20 as it will save you literally days and days or weeks of study and experimentation, etc.

    http://en.wikipedia.org/wiki/Ajax_%28programming%29
    http://en.wikipedia.org/wiki/JSON
    Last edited by MK27; 04-05-2012 at 08:22 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #24
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    By scratch I mean, learn all of the basics and anything I can. The more knowledge the better, even if it is going to be hard. They told me how they got there program to use the developers tools, got my program to work on CNN. But not on google translate yet. Yes my understanding of web applications is quite small and I will admit it, but I am hoping my determination will help me learn as much as I can. I found the Java script and started going through it with a couple of my associates, we think we understand how to either replicate the process or to just use off their already used process. Our thought was that when you entered in the url to have it run, there had to be some point where it was said to display to the user in the scripts, we found that part and now I am just trying to get it to be brought back out again.

  10. #25
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Angel45
    They told me how they got there program to use the developers tools, got my program to work on CNN. But not on google translate yet.
    So, they really do leverage on Google Chrome developer tools for a standalone program rather than a browser extension? What do you mean by "got my program to work on CNN"?

    Quote Originally Posted by Angel45
    I found the Java script and started going through it with a couple of my associates, we think we understand how to either replicate the process or to just use off their already used process. Our thought was that when you entered in the url to have it run, there had to be some point where it was said to display to the user in the scripts, we found that part and now I am just trying to get it to be brought back out again.
    Yes, that's what I have been talking about: basically do the same thing as the script on Google Translate's website, except that you send the input from your own program and render the translated text in your own program instead.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #26
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    Yeah they really got a standalone program to work, I was a little impressed. It was 800 lines in total but it seems to work. Mine works only to get the source code of the developers tools from CNN on one page. They way I wrote mine is wrong I think, buffer overflow I think is happening. And yes I finally understand what you meant there, I am trying to rewrite it to do that instead.

  12. #27
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Angel45
    Yeah they really got a standalone program to work, I was a little impressed. It was 800 lines in total but it seems to work. Mine works only to get the source code of the developers tools from CNN on one page.
    Well, I'm impressed that they got it to work too, though I would not be impressed if all they used it for was to get the source code of a page.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #28
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    It gets the source code and all the java scripts ran, from both sides. It runs real slow though, takes like 7 seconds to work just once.

  14. #29
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Angel45 View Post
    It gets the source code and all the java scripts ran, from both sides. It runs real slow though, takes like 7 seconds to work just once.
    Do you mean, it gets all the relevent .html, .css, and .js files? I don't understand why this would take any number of seconds beyond the transmission time.

    What language is it in? Aren't the chrome developer tools in js -- how are you running that? Spidermonkey? V8?

    Sans the google chrome developer tools, but presuming there is an html parsing lib and http client module available, this shouldn't take more than a few hundred lines in C, I think. I just mention this because it kind of sounds like someone has taken a very wacky, excessively complex route to accomplish a fairly straightforward task, and if you are interested in learning about things like this, you are being led astray...
    Last edited by MK27; 04-06-2012 at 12:45 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  15. #30
    Registered User
    Join Date
    Mar 2012
    Posts
    38
    The reason there is so many lines of code is because the information is being stored into text files everywhere. And everything is getting evaluated twice to get the correct size for malloc to be called. There could be a much more effective way. It gets exactly what the chrome developers tools get, which is .html, with .js as I believe. We technically are not even running that code, we are just collecting and reorganizing it to display just the results which are stored in the code. The reason it has gotten so wacky and complex was because I originally had no idea what I was doing and people just kept adding more code. I am trying to shorten it up a bit. Instead of scanning everything into the file, we are going to change it to just take it in when it meets a certain flag.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The end of Google
    By Mario F. in forum General Discussions
    Replies: 34
    Last Post: 09-22-2010, 12:06 AM
  2. Reading Google Sketchup (.skp) or Google Earth (.kmz)
    By Zeeshan in forum Game Programming
    Replies: 9
    Last Post: 03-07-2008, 05:25 PM
  3. google down
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 07-28-2004, 03:11 PM

Tags for this Thread