Page 1 of 1
Copy a WEB page that is outside the screen
Posted: Sat Sep 16, 2023 6:05 pm
by jak64
Hello everyone,
I sometimes have weird questions...But I'm giving it a go!
My little DELL Latitude 7290 laptop has a resolution of 1366 x 768 pixels but that's enough for me.
Question :
1) With Purebasic, I load a WEB page and move it off the screen with the instructions you gave me (SetWindowPos_(hwnd, #HWND_TOPMOST, 1366, 0, 1366, 768, #SWP_NOZORDER).
Is it possible, when the window is outside the screen, to do a CTRL + A followed by a CTRL + C, in Purebasic, with the corresponding commands that you indicated to me, while this WEB window is off screen?
Thank you for your help
Re: Copy a WEB page that is outside the screen
Posted: Sat Sep 16, 2023 10:53 pm
by infratec
Why you don't simply try it
As long as the window have the focus ... it should work.
Re: Copy a WEB page that is outside the screen
Posted: Sat Sep 16, 2023 11:03 pm
by jak64
Hello infratec,
I tested it but apparently it doesn't work.
If I position the cursor outside the screen, for example in 2000, 300 while my screen is 1366 x 768, the cursor is positioned to the right of my screen, therefore in 1366 and not in 2000
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 1:04 am
by Kuron
from ChatGPT:
Javascript method:
This code will collect all the text content on the page and copy it to your clipboard using the copy() function.
Code: Select all
var allText = "";
var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.nodeType === Node.TEXT_NODE) {
allText += element.textContent;
}
}
copy(allText);
PureBasic method:
Yes, you can use PureBasic to create a program that retrieves and copies the text content of a web page, even if it's not visible in the browser window. To do this, you'll need to use PureBasic's ability to interact with web content through HTTP requests. Here's a high-level overview of how you can achieve this:
Send an HTTP GET Request: Use PureBasic's HTTPRequest functions (e.g., HTTPRequest()) to send an HTTP GET request to the URL of the web page you want to scrape.
Retrieve the Page Content: After sending the GET request, you'll receive the web page's HTML content in response. You can store this content in a string variable.
Extract the Text: You'll need to parse the HTML content to extract the text you want. PureBasic doesn't have built-in HTML parsing capabilities, so you may need to use regular expressions, string manipulation functions, or external libraries like "libxml2" or "htmlcxx" to parse and extract the text content.
Copy the Text to the Clipboard: Once you've extracted the text, you can use PureBasic's clipboard functions (e.g., Clipboard()) to copy the text to the clipboard.
Here's a simplified example of PureBasic code to give you an idea of how this might look:
Code: Select all
; Send an HTTP GET request
HTTPRequest(0, "https://example.com", "", "")
; Check if the request was successful
If HTTPStatus(0) = 200
; Retrieve the page content
HTTPReadString(0, *PageContent)
; Close the HTTP request
HTTPClose(0)
; Extract the text content (you'll need to implement this)
ExtractText(*PageContent, *ExtractedText)
; Copy the extracted text to the clipboard
Clipboard(*ExtractedText)
; Clean up
FreeMemory(*PageContent)
FreeMemory(*ExtractedText)
Else
MessageRequester("Error", "Failed to retrieve the web page.")
EndIf
Procedure ExtractText(*PageContent.s, *ExtractedText.s)
; Implement your logic to extract text from HTML here
; You may use regular expressions, string manipulation, or a library like libxml2
EndProcedure
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 1:29 am
by jak64
Hello Kuron,
Thank you for your response, I will look at it tomorrow, in France, it is 2:30 a.m., I am going to bed.
See you
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 7:03 pm
by jak64
Hello Kuron,
I tested the code you posted.
When launching, I get the error:
"Line 2: Wrong parameter type: expected number instead of a string".
I changed line 2
of "HTTPRequest(0, "
https://google.com", "", "")
in HTTPRequest(0, "
https://google.com", "", 0).
I restart and now I have another error:
"Line 5: HTTPStatus() is not a function, array, macro or list".
thanks for your help
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 7:17 pm
by Kuron
ChatGPT isn't perfect, but it was worth a try.
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 7:26 pm
by jak64
I don't understand !
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 7:43 pm
by Kuron
Read the first line in my post helping you. from ChatGPT:
ChatGPT provided your help, not me. It is not always accurate, but does point you in the right direction.
Re: Copy a WEB page that is outside the screen
Posted: Sun Sep 17, 2023 7:44 pm
by jak64
Ok