繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> Build a Google Language Translation Service Web Scraper Library

Build a Google Language Translation Service Web Scraper Library

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:Recently a buddy and I were discussing various language translation services and applications, and that caused me to think and revisit the Google Language Tools page. It's something I try not to d...

Recently a buddy and I were discussing various language translation services and applications, and that caused me to think and revisit the Google Language Tools page. It's something I try not to do too much of (think, that is, not visit Google), but after years of practice, I just can't stop! It's interesting how Americans are primarily vertical thinkers, and that, only through careful study, can one begin to break this unproductive habit and become a lateral thinker. Lateral thinking is far more productive for things like programming and problem solving. If you don't know what it is, I suggest you start with Dr. Edward DeBono's works.

I whipped out my Google developer key and looked around, but (at least on the first pass) I could not find anything about a published Web API for this service. So, I visited the page and performed (GASP!) the most famous technique that professional guru - level web developers ever learn: VIEW SOURCE!

Turns out that the portion of the page that accepts a TEXTAREA full of text, accepts a chosen Language Pair (e.g. "From|To", and submits the form is elegantly simple. And, the HTML that comes back is also relatively simple. I cannot understand why no web API for this, but ...

So I said to myself, "Self, you haven't done any web scraping for a while, how about let's hammer out this little puppy?" So, I did. Looked around on my hard drives for some nasty web - scrapin' code and couldn't find anything good. I remembered I used to use stuff like WebZinc and the freeware HTMLAgilityPack (which I highly recommend), and I decided I'd just look for something new and possibly simpler, just for a "change of tune".

I found "WebWagon" by Jon Vote: www.idioma-software.com. Its great! Not that sophisticated, but for simple scraping jobs, not bad at all. If you've followed any of my stuff here, you probably know that one of my credos is "don't reinvent the wheel". By looking at other people's code, learning how it works, and then adding to or improving it, we not only get the job done faster, we also become better developers. That's why I'm big on writing articles that share code, and my samples at GotdotNet.com have been downloaded over 34,000 times as of this writing. It's just my way of giving back to the developer community that has been so generous and selfless in helping me to grow as a developer.

Now! After I had picked myself off the floor from giggling about the funny name, I set to work. All I really needed that was "extra" was some code to handle parsing the string value out of the correct returned