I want to control a webpage loaded in web browser. Can XUL be useful for fulfilling this requirement?
A:
Anything which allows you to inject DOM events or script tags can be used to control a web page. XUL is a language for describing GUIs and isn't useful for that.
Here are some examples of how you can control a webpage. You didn't provide any details as to what you intend to do with said control (Browser extension, background scripting, etc.), so I'll give examples for all cases I can think of:
If you want to remote-control web pages as part of a script independent from your normal browser, here are your options:
- If you don't need to run the site's Javascript, use a pseudo-browser like Mechanize for Perl, Python, or Ruby or possibly Twill if you're shell scripting. They're lighter than something that actually executes Javascript, but they'll still handle cookies and let you fill out forms and click links programatically.
- If you do need to run the site's javascript, the simplest solution is to write a Python script which uses PyQt with QWebView but doesn't actually have to show any windows. QtWebKit provides an interface inspired by jQuery for twiddling around in the site's DOM and the ability to inject Javascript and that's all you need to remote-control a web page. (QtWebKit does require that a GUI be running on Linux, but you don't need to actually show any windows to use it.) The necessary QtWebKit APIs should also be present in the Qt bindings for any other language you may prefer.
- If you can't use QtWebKit but need Javascript (perhaps you're writing a GTK+ application), your options are much more limited, but any browser widget out there should at least support injecting new
<script>
tags to control the page. This answer (also mine) has a list of web widgets for various Python toolkits and most (probably all) of them are available for other languages as well. You'll also want to read the instructions for writing userscripts.
If you want to script a webpage inside your existing browser (perhaps to hide ads or skip nag screens on pages you visit frequently), here are your options:
- If you want to modify the browser itself, write a browser extension. This is probably why you were asking about XUL. What you really should be asking about is Javascript (The parts of Firefox and Chrome extensions that actually do things are written in Javascript. XUL is just for laying out windows in Firefox.)... specifically, what Chrome calls Content Scripts. Firefox is too complex internally for me to have bothered to learn the equivalent terminology.) This is your most powerful option, but it's also the most involved and your extension will only work with one browser.
- If you just want to modify or control the website, write a userscript. Userscripts are bits of Javascript which the browser injects into pages of your choice. They're supported in some form or other by Firefox with Greasemonkey, Chrome, Opera, various lesser-known browsers, and, with the IE7Pro extension, by Internet Explorer 7 and 8. They can't modify the browser's interface, but aside from that, they're pretty powerful. (example)
ssokolow
2010-09-20 06:13:29
What actually I want to do is the I want to login in my GMail account automatically. Then I want to place an Email from my Database in the To: field. Then I want to place the content from a Text file in the Content area of the Mail and then I want to send the Mail. and I want to repeat all these steps as many times as all my leads do not gets their emails.
Kuldeep Chand
2010-09-20 08:12:48
What and how should I do to fulfill this requirement. and which language can fulfill this requirement? Thanks for your detailed post.
Kuldeep Chand
2010-09-20 08:13:40
If you want to send mail, the proper way (and the simplest and most reliable too) is to use SMTP to send mail directly, just like native mail clients do, rather than cooking up a fragile "automate GMail's web interface" hack. If you tell me what language you're working in, I can tell you how to do it, but please create another question and link me to it so we don't clutter up this one.
ssokolow
2010-09-20 09:21:07
Also, you'll want to mark my answer (or possibly another one, if you decide to wait and someone else gives a better answer) as "Best Answer". That rewards both of us with points and contributes toward your "accept rate" score. (Your accept rate is sort of like an eBay score. People generally don't bother to answer questions if the asker has a low accept rate.)
ssokolow
2010-09-20 09:23:43