Forum > Beginners
[solved] Get the Text of a HTML-Page (like it's shown on your screen) into a txt
Kevin95:
Hello :)
First things first: I am from Germany, so my English isn't the best, sorry O:-)
I learnt the basics of FreePascal in university (engineers have to learn the basics there), so I'm not very skilled in writing some complex programs.
I would like to write a program which writes down what's written on the screen in your browser (thats the body, isn't it?). Just like as if you visited this webpage, pressed Alt+A, then Alt+C, and lastly pasted in with Alt+V in a textfile and saved it.
I read about fphttpclient, but my little knowledge is not enough to understand it. I tried the following and I allways get RunError2 or Unknown Errors...
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program BodyAuslesen;{$mode objfpc}{$H+}usessysutils,fphttpclient;var t:textfile;begin assignfile(t,'Weber.txt'); reset(t); WriteLn(t,TFPHTTPClient.SimpleGet('https://trainingslager.onlineliga.de/#url=/player/overview?playerId=28056')); readln; closefile(t);end.
The error is in line 10.
I hope the problem isn't hard to solve or anything big O:-)
Thanks for your attention. I’m looking forward to your reply :)
jamie:
Something tells me you miss a few steps....
Looking at your code there.
TFP...
^
tells me you need to create an instant of that object and you are calling the class directly..
Var
FPHttpClient :TFpHttpClient;
Begin
FpHttpClient := TFpHttpClient.Create…….
and in your code
Writenln(t, fpHttpClient……..
I can't say that will work but I can venture to guess it will work better! :D
P.S.
I forgot, make sure you free it when done
FpHttpClient.Free;
wp:
Two problems
(1) You did not open the text file for writing. You must call "Rewrite(t)", not "Reset(t)"
(2) This is a https url. Therefore you must put the dlls "libeay32.dll" and "ssleay32.dll" into the folder which contains the exe of your program. ATM, I don't know where you can find a good download site, but just use the forum's search function, there were several post regarding using fphttpclient with SSL. Be careful to use the correct bitness: if you create a 32-bit program use the 32-bit dlls, and if you create a 64-bit program use the 64-bit dlls (IIRC, even the 64-bit dlls have the "32" in their name!)
@jamie: SimpleGet is a class function, therefore, you need not create an instance of the class.
jamie:
Well Slap my butt....
:o
P.S.
I am using the ICS set of files slated for my old D3 compiler. I didn't bother to attempt compile them into a installable component, But I converted what
I needed to get the files to work in Lazarus so I could port over an app..
Currently I have HttpClient, Ftpclient, FptServer etc that all work but I don't have the SSL version...
I wonder if the author would be interested in making a package set for Lazarus ?
lucamar:
--- Quote from: Kevin95 on November 03, 2018, 03:02:38 pm ---I would like to write a program which writes down what's written on the screen in your browser (thats the body, isn't it?). Just like as if you visited this webpage, pressed Alt+A, then Alt+C, and lastly pasted in with Alt+V in a textfile and saved it.
--- End quote ---
Do note that your code will save the full HTML page as it's come from the server; i.e. including HEAD, all the tags, etc. You'll have to parse it to get the text as it appears in your screen.
Navigation
[0] Message Index
[#] Next page