0

This is in C Language

I want to know how i can write a program to lookup all the input fields of a website. Any website. and then can fill them in. I can write the simple webbrowser in vbs but how can i analyse the input fields. even better would be is i could click the lookup field and it puts the name of it in a box..... that would be ideal. Anyone can help? thanks :)

Oli
  • 11
  • 1
  • 3

1 Answers1

2

Are you sure you want to do this in C?

I ask because it is not easy. First of all, you need to be able to run the HTTP GET request against the webpage you wish to view. For this, you probably need libcurl; you definitely don't want to be writing from scratch at any rate.

Next, you need to process the html you get, finding all input fields. You do NOT want to do this using regular expressions, if anything for the sake of bobince's blood pressure. HTML is not a regular language is the bit you need to take away - you need an xml parser. Enter libxml. I'm sure there are other xml libraries out there, and even libraries for parsing html.

Finally, having done that (got the fields etc) you need to be able to populate them and submit the correct request as per the ACTION and METHOD parameters of the FORM.

This is of course assuming you know what the fields should be formatted with. And it also assumes nothing else is going on. If you have a javascript validated web form (I sincerely hope they're validating on the request too, but they might provide feedback via JS) you won't benefit from that (unless you're going to integrate JS, in which case you might as well write a browser).

This is not a trivial task and it is the reason there are accessibility standards for HTML, because otherwise it becomes tricky to interpret the form without human interaction.

Of course, this all assumes said html is well formed, which isn't always the case...

I might suggest another approach. BeautifulSoup is a well known Python web scraping library that works very well. Python as a language allows easier string manipulation too, which will dramatically cut down your development time. I'd suggest giving the need to use C some serious thought given the size and complexity of the task you want to undertake vs your need to get a result quickly. If you have a lot of time, by all means go for C.

Community
  • 1
  • 1
  • ha wow! well thx atleast for making the effort to reply! i think that will get me going for a while.... A lot of new things there. I had two last questions, should i do a WebBrowser in the program or can i get everything from a link? and being able to connect click with a mouse on a input field and link it to another input field on a different site so that the same thing is wrtten there, is that possible? but thx for ure help, im gonna get cracking on httpget first :P – Oli Jan 09 '11 at 16:25
  • I really wouldn't recommend re-building a web browser... if you have a URI, you can simply send the request you need and get the result in the HTTP Response. On linux, try: `curl http://stackoverflow.com/questions/4639981/lookut-field-webbrowser-c-language`. That'll print the HTTP response for this web page. Then all you need to do is parse that... –  Jan 09 '11 at 16:31
  • Without knowing what your objective is, it is hard to say where or how best to implement something like this. If you're looking to provide accessibility and/or a password manager you might be better with a web browser addon (a Firefox/IE/... extension) rather than writing a whole separate app. –  Jan 09 '11 at 16:34
  • As to linking across websites, that's difficult, but not impossible. Can you match based on different ` –  Jan 09 '11 at 16:35
  • yeah, i seem to understand that all, but what i dont get is how to make it interactive with the mouse. Make an external program selecting a input box on website A with the mouse, then via the program, selecting a button like "=" and then going to a random other website B selecting a input box there. The being able to write in either one of the website and it appears as on the othersite as well, when they are both open..... its like copy paste, but than via a program. and you can deside which input boxes to link. – Oli Jan 09 '11 at 17:06
  • That would be difficult and platform-specific. Even most password managers don't do this - they just substitute values based on urls and remembered fields. You can trigger a click event by using the `SendMessage` (http://msdn.microsoft.com/en-us/library/ms644950%28v=vs.85%29.aspx) function on Windows, but you need to find the form button handle first and I don't know if all browsers render buttons as Windows. Certainly not all web pages do. –  Jan 09 '11 at 19:58