You are not logged in.

Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "andyknownasabu" started this thread

Posts: 5

Location: Karlsruhe

Occupation: Student

  • Send private message

1

Friday, October 22nd 2004, 3:52pm

KHTMLPart - fill form, parse document...

Hi everybody,

I want to open a webpage with a KHTMLPart, fill in predefined values in a form and I also want to be able parse the document structure to select some tags/values.

As a first step I tried to just open an URL and print out the title of the page.
Unfortunately my code doesn't work and I wasn't able to find a solution or tutorial on this topic. Can anybody help me? Thanks in advance!

Source code

1
2
3
4
5
6
KURL url = "http://www.google.de";
browser = new KHTMLPart();
browser->openURL(url);
DOM::HTMLDocument document = browser->htmlDocument();
DOM::DOMString title = document.title();
cout << title.string() << endl;

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

2

Friday, October 22nd 2004, 4:45pm

Maybe you have exactly that code in your program and don't properly return after openURL(), thus not letting the the part time to actually fetch the data from the server.

Cheers,
_
Qt/KDE Developer
Debian User

  • "andyknownasabu" started this thread

Posts: 5

Location: Karlsruhe

Occupation: Student

  • Send private message

3

Monday, October 25th 2004, 1:29pm

Well... at least I receive the cookies because I see a cookie dialog to select whether they should be saved or not. Anything else that could be wrong? What about the code, should it work in your opinion?

This post has been edited 1 times, last edit by "andyknownasabu" (Oct 25th 2004, 1:29pm)


anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

4

Tuesday, October 26th 2004, 5:35am

Well, the code already works.
You request an URL but don't let the process any time to actually get the data, so the document is empty.

I suggest to let KHTML get some data before you request any data from it :)

Cheers,
_
Qt/KDE Developer
Debian User

  • "andyknownasabu" started this thread

Posts: 5

Location: Karlsruhe

Occupation: Student

  • Send private message

5

Tuesday, October 26th 2004, 8:10am

Well, OK ;) Thanks for your answer!

But how can I accomplish that?
Just inserting a sleep(10) can't be a good solution and this also doesn't work: I get no output of the page title... :(

I wasn't able to find a signal which says "page loading finished" or something like that...

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

6

Tuesday, October 26th 2004, 8:14pm

Quoted

Originally posted by andyknownasabu
But how can I accomplish that?

returning from the slot and react on the signal indicating the end of the data transfer

Quoted


Just inserting a sleep(10) can't be a good solution and this also doesn't work: I get no output of the page title... :(

sleep just keeps the thread from executing, i.e. it does nothing for a period of time.
But "nothing" also means it is not fetching data :)

Quoted


I wasn't able to find a signal which says "page loading finished" or something like that...


completed()?

Cheers,
_
Qt/KDE Developer
Debian User

  • "andyknownasabu" started this thread

Posts: 5

Location: Karlsruhe

Occupation: Student

  • Send private message

7

Wednesday, October 27th 2004, 1:31pm

THANK YOU VERY MUCH! I didn't recognize that signal but connecting it to the appropriate slot works as requested :))

Now, the next question is how to input data into forms using khtml functions (for example username/password input forms):

Source code

1
2
3
4
DOM::HTMLDocument document = browser->htmlDocument();
DOM::HTMLCollection forms = document.forms();
DOM::Node useridNode = forms.namedItem("userid");
DOM::Node passNode = forms.namedItem("pass");


Is HTMLInputElement the right starting point?

This post has been edited 3 times, last edit by "andyknownasabu" (Oct 27th 2004, 1:52pm)


anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

8

Thursday, October 28th 2004, 5:57pm

Are you using KHTML just to parse the data or do you also use it for display?

Cheers,
_
Qt/KDE Developer
Debian User

  • "andyknownasabu" started this thread

Posts: 5

Location: Karlsruhe

Occupation: Student

  • Send private message

9

Thursday, October 28th 2004, 6:03pm

I want to use KHTML to parse the document, find the desired forms (later also different DOM elements and attributes, because I want to import data from websites into my program), fill in values and submit these values (for example automatic login).
I don't need to display pages, I only want it to input data into my program.

This post has been edited 1 times, last edit by "andyknownasabu" (Oct 28th 2004, 6:04pm)


anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

10

Sunday, November 7th 2004, 8:44pm

I am not sure if it is possible to activate a button element of the DOM tree.
Maybe by inserting some script code into the document and having it executed.

You could alternatively get all information about the form from the DOM tree and then create a create appropriate response data yourself and send that through a HTTP ioslave.

Cheers,
_
Qt/KDE Developer
Debian User

11

Tuesday, July 18th 2006, 1:27pm

I have been searching all over the place - is there any tutorial that shows how to do this with a scripting language such as Python or PERL?

Any pointers in the right direction are gratefully received